import { z } from 'zod';
import { InputType } from '../../types';

/**
 * Base schema for all filter input types.
 * Contains common properties that all filter inputs must have.
 *
 * @property group - Group identifier that this input belongs to
 * @property key - Unique identifier for the input within its group
 * @property label - Optional display name for the input
 * @property description - Optional detailed explanation of the input
 * @property type - The type of input control (Text, Checkbox, DateRange)
 */
export const BaseFilterInputSchema = z
  .object({
    group: z
      .string()
      .describe(
        'Identifier for the group this filter input belongs to. Used for organizing related filters.',
      ),
    key: z
      .string()
      .describe(
        'Unique identifier for this input within its group. Used as a key in requests and state management.',
      ),
    label: z
      .string()
      .optional()
      .describe('Human-readable display name shown to users in the UI.'),
    description: z
      .string()
      .optional()
      .describe(
        'Detailed explanation of what this filter does, displayed as helper text in the UI.',
      ),
    type: z
      .nativeEnum(InputType)
      .describe(
        'Determines the type of input control and its behavior (Text, Checkbox, DateRange, etc.).',
      ),
    target: z
      .union([z.literal('filter'), z.literal('input')])
      .default('input') // TODO: Fix settings before removing default (qs settings dont have target yet, but needs to be there)
      .describe(
        'Specifies whether this input is part of the main query parameters or filter parameters.',
      ),
  })
  .describe('BaseFilterInput');

export type BaseFilterInput = z.infer<typeof BaseFilterInputSchema>;
