import {
  BuyerTypeSchema,
  EntitySchema,
  KeyValueOfStringAndStringSchema,
  NotificationChannelSchema,
} from '@isa/common/data-access';
import { z } from 'zod';
import { DisplayAddresseeSchema } from './display-addressee.schema';
import { DisplayBranchSchema } from './display-branch.schema';
import { DisplayLogisticianSchema } from './display-logistician.schema';
import { DisplayOrderItemSchema } from './display-order-item.schema';
import { DisplayOrderPaymentSchema } from './display-order-payment.schema';
import { EnvironmentChannelSchema } from './environment-channel.schema';
import { LinkedRecordSchema } from './linked-record.schema';
import { OrderTypeSchema } from './order-type.schema';
import { TermsOfDeliverySchema } from './terms-of-delivery.schema';

export const DisplayOrderSchema = z
  .object({
    actions: z
      .array(KeyValueOfStringAndStringSchema)
      .describe('Actions')
      .optional(),
    buyer: DisplayAddresseeSchema.describe('Buyer information').optional(),
    buyerComment: z.string().describe('Buyer comment').optional(),
    buyerIsGuestAccount: z
      .boolean()
      .describe('Buyer is guest account')
      .optional(),
    buyerNumber: z
      .string()
      .describe('Unique buyer identifier number')
      .optional(),
    buyerType: BuyerTypeSchema.describe('Buyer type').optional(),
    clientChannel:
      EnvironmentChannelSchema.describe('Client channel').optional(),
    completedDate: z.string().describe('Completed date').optional(),
    features: z.record(z.string().describe('Features'), z.string()).optional(),
    items: z.array(DisplayOrderItemSchema).describe('List of items').optional(),
    itemsCount: z.number().describe('Number of itemss').optional(),
    linkedRecords: z
      .array(LinkedRecordSchema)
      .describe('List of linked records')
      .optional(),
    logistician: DisplayLogisticianSchema.describe(
      'Logistician information',
    ).optional(),
    notificationChannels: NotificationChannelSchema.describe(
      'Notification channels',
    ).optional(),
    orderBranch: DisplayBranchSchema.describe('Order branch').optional(),
    orderDate: z.string().describe('Order date').optional(),
    orderNumber: z.string().describe('Order number').optional(),
    orderType: OrderTypeSchema.describe('Order type'),
    orderValue: z.number().describe('Order value').optional(),
    orderValueCurrency: z.string().describe('Order value currency').optional(),
    payer: DisplayAddresseeSchema.describe('Payer information').optional(),
    payerIsGuestAccount: z
      .boolean()
      .describe('Payer is guest account')
      .optional(),
    payerNumber: z.string().describe('Unique payer account number').optional(),
    payment: DisplayOrderPaymentSchema.describe('Payment').optional(),
    shippingAddress: DisplayAddresseeSchema.describe(
      'Shipping address information',
    ).optional(),
    targetBranch: DisplayBranchSchema.describe('Target branch').optional(),
    termsOfDelivery:
      TermsOfDeliverySchema.describe('Terms of delivery').optional(),
  })
  .extend(EntitySchema.shape);
