import { z } from 'zod';
import { BaseFilterInputSchema } from './base-filter-input.schema';
import { InputType } from '../../types';
import { CheckboxFilterInputOptionSchema } from './checkbox-filter-input-option.schema';

/**
 * Schema for checkbox-based filter inputs that allow users to select from multiple options.
 * Extends the BaseFilterInputSchema with checkbox-specific properties.
 *
 * @property type - Must be InputType.Checkbox
 * @property maxOptions - Optional limit on how many options can be selected simultaneously.
 *   When set, the filter service enforces this limit using a FIFO (First In, First Out) strategy,
 *   automatically removing the oldest selections when new selections would exceed the limit.
 *   When configured, the "Select All" control is hidden to prevent user confusion.
 * @property options - Array of selectable checkbox options
 * @property selected - Array of string values representing the currently selected options
 *
 * @example
 * ```typescript
 * // Checkbox input with maximum of 3 selections
 * const checkboxInput: CheckboxFilterInput = {
 *   type: InputType.Checkbox,
 *   key: 'categories',
 *   label: 'Categories',
 *   maxOptions: 3, // Users can select up to 3 categories
 *   options: [...],
 *   selected: ['electronics', 'books']
 * };
 * ```
 */
export const CheckboxFilterInputSchema = BaseFilterInputSchema.extend({
  type: z
    .literal(InputType.Checkbox)
    .describe(
      'Specifies this as a checkbox input type. Must be InputType.Checkbox.',
    ),
  maxOptions: z
    .number()
    .optional()
    .describe(
      'Optional maximum number of options that can be selected simultaneously. ' +
        'When exceeded, the oldest selections are automatically removed (FIFO strategy). ' +
        'Setting this value also hides the "Select All" control to prevent user confusion.',
    ),
  options: z
    .array(CheckboxFilterInputOptionSchema)
    .describe('List of available checkbox options that users can select from.'),
  selected: z
    .array(z.string())
    .describe(
      'Array of values representing which options are currently selected. Each value corresponds to the value property of an option.',
    ),
}).describe('CheckboxFilterInput');

export type CheckboxFilterInput = z.infer<typeof CheckboxFilterInputSchema>;
