import {
  AddressSchema,
  CommunicationDetailsSchema,
  EntityContainerSchema,
  EntitySchema,
  GenderSchema,
  LabelSchema,
  OrganisationSchema,
  PayerType,
} from '@isa/common/data-access';
import { z } from 'zod';
import { PayerStatusSchema } from './payer-status.schema';
import { PaymentSettingsSchema } from './payment-settings.schema';

export const PayerSchema = z
  .object({
    address: AddressSchema.describe('Address').optional(),
    agentComment: z.string().describe('Agent comment').optional(),
    communicationDetails: CommunicationDetailsSchema.describe(
      'Communication details',
    ).optional(),
    deactivationComment: z.string().describe('Deactivation comment').optional(),
    defaultPaymentPeriod: z
      .number()
      .describe('Default payment period')
      .optional(),
    firstName: z.string().describe('First name').optional(),
    gender: GenderSchema.describe('Gender').optional(),
    isGuestAccount: z.boolean().describe('Whether guestAccount').optional(),
    label: EntityContainerSchema(LabelSchema).describe('Label').optional(),
    lastName: z.string().describe('Last name').optional(),
    organisation: OrganisationSchema.describe(
      'Organisation information',
    ).optional(),
    payerGroup: z.string().describe('Payer group').optional(),
    payerNumber: z.string().describe('Unique payer account number').optional(),
    payerStatus: PayerStatusSchema.describe(
      'Current status of the payer account',
    ).optional(),
    payerType: z.nativeEnum(PayerType).describe('Payer type').optional(),
    paymentTypes: z
      .array(PaymentSettingsSchema)
      .describe('Payment types')
      .optional(),
    standardInvoiceText: z
      .string()
      .describe('Standard invoice text')
      .optional(),
    statusChangeComment: z
      .string()
      .describe('Status change comment')
      .optional(),
    statusComment: z.string().describe('Status comment').optional(),
    title: z.string().describe('Title').optional(),
  })
  .extend(EntitySchema.shape);

export type CrmPayer = z.infer<typeof PayerSchema>;
