import { z } from 'zod';

/**
 * Schema for defining order-by parameters in queries.
 * Used for sorting search results.
 */
export const OrderBySchema = z.object({
  by: z.string().describe('Field name to sort by'),
  label: z.string().describe('Display label for the sort option'),
  desc: z.boolean().describe('Whether sorting is descending'),
  selected: z.boolean().describe('Whether this sort option is currently selected'),
});

/**
 * Schema for validating and parsing query tokens.
 * Used for search operations to ensure consistent query structure.
 */
export const QueryTokenSchema = z.object({
  filter: z.record(z.any()).describe('Filter criteria as key-value pairs').default({}),
  input: z.record(z.string()).describe('Input parameters as key-value pairs').default({}).optional(),
  orderBy: z.array(OrderBySchema).describe('Sorting parameters').default([]).optional(),
  skip: z.number().describe('Number of items to skip for pagination').default(0),
  take: z.number().describe('Number of items to return per page').default(25),
});

/**
 * Type representing the structure of a query token.
 * Generated from the Zod schema for type safety.
 */
export type QueryToken = z.infer<typeof QueryTokenSchema>;
export type QueryTokenInput = z.input<typeof QueryTokenSchema>;
