/**
 * Catalog Domain - Salesforce Provider Raw Types
 * 
 * Raw Salesforce API response types for Product2 and PricebookEntry sobjects.
 */

import { z } from "zod";

// ============================================================================
// Salesforce Product2 Record (Raw API Response)
// ============================================================================

export const salesforceProduct2RecordSchema = z.object({
  Id: z.string(),
  Name: z.string().optional(),
  StockKeepingUnit: z.string().optional(),
  Description: z.string().optional(),
  Product2Categories1__c: z.string().nullable().optional(),
  Portal_Catalog__c: z.boolean().nullable().optional(),
  Portal_Accessible__c: z.boolean().nullable().optional(),
  Item_Class__c: z.string().nullable().optional(),
  Billing_Cycle__c: z.string().nullable().optional(),
  Catalog_Order__c: z.number().nullable().optional(),
  Display_Order__c: z.number().nullable().optional(),
  Auto_Add__c: z.boolean().nullable().optional(),
  Is_Default__c: z.boolean().nullable().optional(),
  Bundled_Addon__c: z.string().nullable().optional(),
  Is_Bundled_Addon__c: z.boolean().nullable().optional(),
  Internet_Plan_Tier__c: z.string().nullable().optional(),
  Internet_Offering_Type__c: z.string().nullable().optional(),
  Feature_List__c: z.string().nullable().optional(),
  SIM_Data_Size__c: z.string().nullable().optional(),
  SIM_Plan_Type__c: z.string().nullable().optional(),
  SIM_Has_Family_Discount__c: z.boolean().nullable().optional(),
  VPN_Region__c: z.string().nullable().optional(),
  WH_Product_ID__c: z.number().nullable().optional(),
  WH_Product_Name__c: z.string().nullable().optional(),
  Price__c: z.number().nullable().optional(),
  Monthly_Price__c: z.number().nullable().optional(),
  One_Time_Price__c: z.number().nullable().optional(),
  CreatedDate: z.string().optional(),
  LastModifiedDate: z.string().optional(),
});

export type SalesforceProduct2Record = z.infer<typeof salesforceProduct2RecordSchema>;

// ============================================================================
// Salesforce PricebookEntry Record (Raw API Response)
// ============================================================================

export const salesforcePricebookEntryRecordSchema = z.object({
  Id: z.string(),
  Name: z.string().optional(),
  UnitPrice: z.union([z.number(), z.string()]).nullable().optional(),
  Pricebook2Id: z.string().nullable().optional(),
  Product2Id: z.string().nullable().optional(),
  IsActive: z.boolean().nullable().optional(),
  Product2: salesforceProduct2RecordSchema.nullable().optional(),
  CreatedDate: z.string().optional(),
  LastModifiedDate: z.string().optional(),
});

export type SalesforcePricebookEntryRecord = z.infer<typeof salesforcePricebookEntryRecordSchema>;

// ============================================================================
// Salesforce Product2 With PricebookEntries (Query Result)
// ============================================================================

export const salesforceProduct2WithPricebookEntriesSchema = salesforceProduct2RecordSchema.extend({
  PricebookEntries: z.object({
    records: z.array(salesforcePricebookEntryRecordSchema).optional(),
  }).optional(),
});

export type SalesforceProduct2WithPricebookEntries = z.infer<typeof salesforceProduct2WithPricebookEntriesSchema>;
