import { z } from 'zod';

/**
 * Base schema for checkbox filter input options.
 * 
 * Represents a single checkbox option within a hierarchical filter structure.
 * Each option has a unique path that identifies its position in the hierarchy.
 */
const CheckboxFilterInputOptionBaseSchema = z
  .object({
    path: z
      .array(z.string())
      .describe(
        'Path to the option, useful for nested structures. Starts with the group key and includes all parent keys.',
      ),
    key: z.string().describe('Unique identifier for the checkbox option.'),
    label: z
      .string()
      .describe('Display text shown next to the checkbox in the UI.'),
    value: z
      .string()
      .optional()
      .describe(
        'Underlying value that will be sent in requests when this option is selected.',
      ),
  })
  .describe('CheckboxFilterInputOption');

/**
 * Schema for checkbox filter input options with support for nested hierarchical structures.
 *
 * Extends the base checkbox filter input option schema to include an optional `values`
 * array that can contain nested CheckboxFilterInputOption instances, enabling multi-level
 * checkbox filtering capabilities.
 *
 * @example
 * ```typescript
 * const filterOption = {
 *   // base properties from CheckboxFilterInputOptionBaseSchema
 *   values: [
 *     // nested checkbox options
 *   ]
 * };
 * ```
 */
export const CheckboxFilterInputOptionSchema =
  CheckboxFilterInputOptionBaseSchema.extend({
    values: z
      .array(CheckboxFilterInputOptionBaseSchema)
      .optional()
      .describe('Array of CheckboxFilterInputOption for nested options.'),
  });

export type CheckboxFilterInputOption = z.infer<
  typeof CheckboxFilterInputOptionSchema
>;
