/**
 * WHMCS Catalog Provider - Raw Types
 *
 * Type definitions for raw WHMCS API responses related to catalog/products.
 */

import { z } from "zod";
import {
  whmcsString as s,
  whmcsRequiredNumber,
} from "../../../common/providers/whmcs-utils/index.js";

// ============================================================================
// WHMCS Catalog Product Pricing Cycle
// ============================================================================

const whmcsCatalogProductPricingCycleSchema = z.object({
  prefix: s,
  suffix: s,
  msetupfee: s,
  qsetupfee: s,
  ssetupfee: s,
  asetupfee: s,
  bsetupfee: s,
  tsetupfee: s,
  monthly: s,
  quarterly: s,
  semiannually: s,
  annually: s,
  biennially: s,
  triennially: s,
});

// ============================================================================
// WHMCS Catalog Product
// ============================================================================

const whmcsCatalogProductSchema = z.object({
  pid: s,
  gid: whmcsRequiredNumber,
  name: s,
  description: s,
  module: s,
  paytype: s,
  pricing: z.record(z.string(), whmcsCatalogProductPricingCycleSchema),
});

export type WhmcsCatalogProduct = z.infer<typeof whmcsCatalogProductSchema>;

// ============================================================================
// WHMCS Catalog Product List Response (GetProducts API)
// ============================================================================

/**
 * WHMCS GetProducts API response schema
 */
export const whmcsCatalogProductListResponseSchema = z.object({
  products: z.object({
    product: z.array(whmcsCatalogProductSchema),
  }),
  totalresults: whmcsRequiredNumber,
});

export type WhmcsCatalogProductListResponse = z.infer<typeof whmcsCatalogProductListResponseSchema>;
