import { z } from 'zod';
import type { LocalizedText } from '@/server/page-layout/types';
import { dealTypeSchema } from '@/lib/deal-types/schema';
import type { DealType } from '@/lib/deal-types';

export interface Config {
  title: LocalizedText;
  filters: {
    dealType?: DealType;
    category?: 'MEAL' | 'BAKERY' | 'BEVERAGE' | 'DESSERT' | 'PACKAGED';
    lowStock?: boolean;
    nearExpiry?: boolean;
  };
  sort: 'recent' | 'trending';
  limit: number;
}

export const configSchema: z.ZodType<Config> = z.object({
  title: z.object({ he: z.string().min(1), en: z.string().min(1) }),
  filters: z.object({
    dealType: dealTypeSchema.optional(),
    category: z.enum(['MEAL', 'BAKERY', 'BEVERAGE', 'DESSERT', 'PACKAGED']).optional(),
    lowStock: z.boolean().optional(),
    nearExpiry: z.boolean().optional(),
  }),
  sort: z.enum(['recent', 'trending']),
  limit: z.number().int().min(1).max(30),
});

export const defaultConfig: Config = {
  title: { he: 'עסקאות חדשות', en: 'Latest deals' },
  filters: {},
  sort: 'recent',
  limit: 10,
};

export const type = 'deal-row:custom-query' as const;
export const category = 'custom' as const;
export const labelKey = 'module_labels.deal-row:custom-query' as const;
