import {
  EntitySchema,
  DateRangeSchema,
  KeyValueOfStringAndStringSchema,
} from '@isa/common/data-access';
import { z } from 'zod';
import { OrderItemProcessingStatusValueSchema } from './order-item-processing-status-value.schema';

// Forward declaration for circular reference
export const DisplayOrderItemSubsetSchema = z
  .object({
    actions: z
      .array(KeyValueOfStringAndStringSchema)
      .describe('Possible actions')
      .optional(),
    compartmentCode: z.string().describe('Compartment code').optional(),
    compartmentInfo: z.string().describe('Compartment information').optional(),
    compartmentStart: z.string().describe('Compartment start').optional(),
    compartmentStop: z.string().describe('Compartment stop').optional(),
    description: z.string().describe('Description text').optional(),
    estimatedDelivery: DateRangeSchema.describe(
      'Estimated delivery date range',
    ).optional(),
    estimatedShippingDate: z
      .string()
      .describe('Estimated shipping date')
      .optional(),
    orderItem: z
      .lazy(() => z.any())
      .describe('Order item')
      .optional(), // Circular reference to DisplayOrderItem
    orderItemSubsetNumber: z
      .string()
      .describe('Order item subset number')
      .optional(),
    preferredPickUpDate: z
      .string()
      .describe('Preferred pick up date')
      .optional(),
    processingStatus:
      OrderItemProcessingStatusValueSchema.describe('Processing status'),
    processingStatusDate: z
      .string()
      .describe('Processing status date')
      .optional(),
    quantity: z.number().describe('Quantity').optional(),
    specialComment: z.string().describe('Special comment').optional(),
    ssc: z.string().describe('SSC code').optional(),
    sscText: z.string().describe('SSC text').optional(),
    supplierLabel: z.string().describe('Supplier label').optional(),
    supplierName: z.string().describe('Supplier name').optional(),
    supplyChannel: z.string().describe('Supply channel').optional(),
    trackingNumber: z.string().describe('Tracking number').optional(),
  })
  .extend(EntitySchema.shape);

export type DisplayOrderItemSubset = z.infer<
  typeof DisplayOrderItemSubsetSchema
>;
