import { z } from 'zod';
import { EntityStatusSchema } from './entity-status.schema';

/**
 * Schema for ExternalReferenceDTO
 * Represents external system reference information
 *
 * Note: In the generated DTOs, externalStatus is REQUIRED when ExternalReferenceDTO is present.
 * However, we make all fields optional in this schema because:
 * 1. This schema is used within EntityReferenceContainerSchema where externalReference itself is optional
 * 2. When constructing objects, we often omit externalReference entirely
 * 3. Type compatibility: our inferred types must be assignable to the generated DTOs
 *
 * When using this schema to create objects that will be passed to generated API clients,
 * either omit externalReference entirely OR ensure externalStatus is provided.
 */
export const ExternalReferenceSchema = z.object({
  externalChanged: z.string().describe('External changed').optional(),
  externalCreated: z.string().describe('External created').optional(),
  externalNumber: z.string().describe('External number').optional(),
  externalPK: z.string().describe('External p k').optional(),
  externalRepository: z.string().describe('External repository').optional(),
  externalStatus: EntityStatusSchema.describe('External status').optional(),
  externalVersion: z.number().describe('External version').optional(),
  publishToken: z.string().describe('Publish token').optional(),
});

export type ExternalReference = z.infer<typeof ExternalReferenceSchema>;
