import { z } from "zod";

export const CheckoutRequestSchema = z.object({
  productId: z.string(),
  placementId: z.string(),
  paywallId: z.string(),
});
export type CheckoutRequest = z.infer<typeof CheckoutRequestSchema>;

export const CheckoutResponseSchema = z.object({
  status: z.string(),
  invoiceId: z.string(),
  paymentUrl: z.string().url(),
});
export type CheckoutResponse = z.infer<typeof CheckoutResponseSchema>;

export const PaymentInfoSchema = z.object({
  productId: z.string(),
  key: z.string(),
  isAutoTopUp: z.boolean().optional(),
});
export type PaymentInfo = z.infer<typeof PaymentInfoSchema>;

export const SingleCheckoutRequestSchema = z.object({
  paymentInfo: PaymentInfoSchema,
  return_url: z.string().optional(),
  pageUrl: z.string().optional(),
});
export type SingleCheckoutRequest = z.infer<typeof SingleCheckoutRequestSchema>;

export const SingleCheckoutSuccessSchema = z.object({
  payment: z.object({
    status: z.string(),
    invoiceId: z.string(),
    paymentUrl: z.string().url().optional(),
  }),
});
export type SingleCheckoutSuccess = z.infer<typeof SingleCheckoutSuccessSchema>;

export const SingleCheckoutErrorSchema = z.object({
  status: z.string(),
  message: z.string(),
});
export type SingleCheckoutError = z.infer<typeof SingleCheckoutErrorSchema>;

export const SingleCheckoutResponseSchema = z.union([
  SingleCheckoutSuccessSchema,
  SingleCheckoutErrorSchema,
]);
export type SingleCheckoutResponse = z.infer<
  typeof SingleCheckoutResponseSchema
>;
