import {
  EntityContainerSchema,
  QuantityUnitTypeSchema,
  TouchBaseSchema,
} from '@isa/common/data-access';
import { z } from 'zod';
import { CategorySchema } from './category.schema';
import { ComponentItemDisplayTypeSchema } from './component-item-display-type.schema';

export const ComponentItemSchema = z
  .object({
    name: z.string().describe('Name').optional(),
    description: z.string().describe('Description text').optional(),
    item: EntityContainerSchema(z.lazy(() => z.any())).describe('Item').optional(), // ItemSchema would create circular dependency
    category: EntityContainerSchema(CategorySchema).describe('Category information').optional(),
    required: z.boolean().describe('Whether this is required').optional(),
    quantityMin: z.number().describe('Quantity min').optional(),
    quantityMax: z.number().describe('Quantity max').optional(),
    quantityUnitType: QuantityUnitTypeSchema.describe('QuantityUnit type').optional(),
    unit: z.string().describe('Unit').optional(),
    displayType: ComponentItemDisplayTypeSchema.describe('Display type').optional(),
    start: z.string().describe('Start').optional(),
    stop: z.string().describe('Stop').optional(),
  })
  .extend(TouchBaseSchema.shape);

export type ComponentItem = z.infer<typeof ComponentItemSchema>;
