import { z } from 'zod';
import {
  EntitySchema,
  EntityContainerSchema,
  AddressSchema,
} from '@isa/common/data-access';

export const CompanySchema: z.ZodType<{
  changed?: string;
  created?: string;
  id?: number;
  pId?: string;
  status?: number;
  uId?: string;
  version?: number;
  parent?: {
    id?: number;
    pId?: string;
    uId?: string;
    data?: any;
  };
  companyNumber?: string;
  locale?: string;
  name?: string;
  nameSuffix?: string;
  legalForm?: string;
  department?: string;
  costUnit?: string;
  vatId?: string;
  address?: {
    street?: string;
    streetNumber?: string;
    zipCode?: string;
    city?: string;
    country?: string;
    additionalInfo?: string;
  };
  gln?: string;
  sector?: string;
}> = EntitySchema.extend({
  parent: z
    .lazy(() => EntityContainerSchema(CompanySchema))
    .describe('Parent')
    .optional(),
  companyNumber: z.string().describe('Company number').optional(),
  locale: z.string().describe('Locale').optional(),
  name: z.string().max(64).describe('Name').optional(),
  nameSuffix: z.string().max(64).describe('Name suffix').optional(),
  legalForm: z.string().max(64).describe('Legal form').optional(),
  department: z.string().max(64).describe('Department').optional(),
  costUnit: z.string().max(64).describe('Cost unit').optional(),
  vatId: z.string().max(16).describe('Vat identifier').optional(),
  address: AddressSchema.describe('Address').optional(),
  gln: z.string().max(64).describe('Gln').optional(),
  sector: z.string().max(64).describe('Sector').optional(),
});

export type Company = z.infer<typeof CompanySchema>;
