/*
 * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
 */

import * as z from "zod/v4-mini";
import { remap as remap$ } from "../../lib/primitives.js";
import { safeParse } from "../../lib/schemas.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
import {
  ProductPriceSource,
  ProductPriceSource$inboundSchema,
  ProductPriceSource$outboundSchema,
} from "./productpricesource.js";
import {
  RecurringInterval,
  RecurringInterval$inboundSchema,
  RecurringInterval$outboundSchema,
} from "./recurringinterval.js";
import {
  TaxBehaviorOption,
  TaxBehaviorOption$inboundSchema,
  TaxBehaviorOption$outboundSchema,
} from "./taxbehavioroption.js";

/**
 * A recurring price for a product, i.e. a subscription.
 *
 * @remarks
 *
 * **Deprecated**: The recurring interval should be set on the product itself.
 */
export type LegacyRecurringProductPriceFixed = {
  /**
   * Creation timestamp of the object.
   */
  createdAt: Date;
  /**
   * Last modification timestamp of the object.
   */
  modifiedAt: Date | null;
  /**
   * The ID of the price.
   */
  id: string;
  source: ProductPriceSource;
  amountType: "fixed";
  /**
   * The currency in which the customer will be charged.
   */
  priceCurrency: string;
  /**
   * The tax behavior of the price. If null, it defaults to the organization's default tax behavior.
   */
  taxBehavior: TaxBehaviorOption | null;
  /**
   * Whether the price is archived and no longer available.
   */
  isArchived: boolean;
  /**
   * The ID of the product owning the price.
   */
  productId: string;
  /**
   * The type of the price.
   */
  type: "recurring";
  recurringInterval: RecurringInterval;
  /**
   * The price in cents.
   */
  priceAmount: number;
  legacy: true;
};

/** @internal */
export const LegacyRecurringProductPriceFixed$inboundSchema: z.ZodMiniType<
  LegacyRecurringProductPriceFixed,
  unknown
> = z.pipe(
  z.object({
    created_at: z.pipe(
      z.iso.datetime({ offset: true }),
      z.transform(v => new Date(v)),
    ),
    modified_at: z.nullable(
      z.pipe(z.iso.datetime({ offset: true }), z.transform(v => new Date(v))),
    ),
    id: z.string(),
    source: ProductPriceSource$inboundSchema,
    amount_type: z.literal("fixed"),
    price_currency: z.string(),
    tax_behavior: z.nullable(TaxBehaviorOption$inboundSchema),
    is_archived: z.boolean(),
    product_id: z.string(),
    type: z.literal("recurring"),
    recurring_interval: RecurringInterval$inboundSchema,
    price_amount: z.int(),
    legacy: z.literal(true),
  }),
  z.transform((v) => {
    return remap$(v, {
      "created_at": "createdAt",
      "modified_at": "modifiedAt",
      "amount_type": "amountType",
      "price_currency": "priceCurrency",
      "tax_behavior": "taxBehavior",
      "is_archived": "isArchived",
      "product_id": "productId",
      "recurring_interval": "recurringInterval",
      "price_amount": "priceAmount",
    });
  }),
);
/** @internal */
export type LegacyRecurringProductPriceFixed$Outbound = {
  created_at: string;
  modified_at: string | null;
  id: string;
  source: string;
  amount_type: "fixed";
  price_currency: string;
  tax_behavior: string | null;
  is_archived: boolean;
  product_id: string;
  type: "recurring";
  recurring_interval: string;
  price_amount: number;
  legacy: true;
};

/** @internal */
export const LegacyRecurringProductPriceFixed$outboundSchema: z.ZodMiniType<
  LegacyRecurringProductPriceFixed$Outbound,
  LegacyRecurringProductPriceFixed
> = z.pipe(
  z.object({
    createdAt: z.pipe(z.date(), z.transform(v => v.toISOString())),
    modifiedAt: z.nullable(z.pipe(z.date(), z.transform(v => v.toISOString()))),
    id: z.string(),
    source: ProductPriceSource$outboundSchema,
    amountType: z.literal("fixed"),
    priceCurrency: z.string(),
    taxBehavior: z.nullable(TaxBehaviorOption$outboundSchema),
    isArchived: z.boolean(),
    productId: z.string(),
    type: z.literal("recurring"),
    recurringInterval: RecurringInterval$outboundSchema,
    priceAmount: z.int(),
    legacy: z.literal(true),
  }),
  z.transform((v) => {
    return remap$(v, {
      createdAt: "created_at",
      modifiedAt: "modified_at",
      amountType: "amount_type",
      priceCurrency: "price_currency",
      taxBehavior: "tax_behavior",
      isArchived: "is_archived",
      productId: "product_id",
      recurringInterval: "recurring_interval",
      priceAmount: "price_amount",
    });
  }),
);

export function legacyRecurringProductPriceFixedToJSON(
  legacyRecurringProductPriceFixed: LegacyRecurringProductPriceFixed,
): string {
  return JSON.stringify(
    LegacyRecurringProductPriceFixed$outboundSchema.parse(
      legacyRecurringProductPriceFixed,
    ),
  );
}
export function legacyRecurringProductPriceFixedFromJSON(
  jsonString: string,
): SafeParseResult<LegacyRecurringProductPriceFixed, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => LegacyRecurringProductPriceFixed$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'LegacyRecurringProductPriceFixed' from JSON`,
  );
}
