/**
 * Product domain model. Public storefront URLs use slug; id is internal.
 */
export type ProductState = 'draft' | 'active' | 'archived';

export const PRODUCT_STATES: readonly ProductState[] = ['draft', 'active', 'archived'];

/** Sales channels. */
export type SalesChannel = 'online' | 'offline' | 'all';

/** Product attribute tags (simple checkboxes). */
export const PRODUCT_ATTRIBUTES = [
  'bio',
  'comercio-justo',
  'congelado',
  'cruelty-free',
  'de-temporada',
  'demeter',
  'fruta-verdura',
  'keto',
  'kosher',
  'low-carb',
  'raw-food',
  'sin-azucar',
  'sin-gluten',
  'sin-lactosa',
  'vegano',
  'zero-waste',
] as const;

export type ProductAttribute = (typeof PRODUCT_ATTRIBUTES)[number];

export interface ProductBrandSummary {
  id: string;
  name: string;
  slug: string;
}

export interface Product {
  id: string;
  name: string;
  slug: string;
  description: string | null;
  state: ProductState;
  channels: SalesChannel;
  featured: boolean;
  attributes: ProductAttribute[];
  seoTitle: string | null;
  seoDescription: string | null;
  categoryIds: string[];
  brandId: string | null;
  brand?: ProductBrandSummary;
  expirationDate: string | null;
  /** Peso unitario en kg (el peso del pedido es cantidad × este valor). */
  unitWeightKg: number;
  /** Cantidad mínima de compra; el frontend bloquea pedidos por debajo. */
  minPurchaseQty: number;
  /** F-112: marcado cuando la ficha fue asistida por IA y debe mostrar disclaimer. */
  aiAssisted: boolean;
  createdAt: Date;
  updatedAt: Date;
}

export interface NewProduct {
  name: string;
  slug: string;
  description?: string | null;
  state?: ProductState;
  channels?: SalesChannel;
  featured?: boolean;
  attributes?: ProductAttribute[];
  seoTitle?: string | null;
  seoDescription?: string | null;
  categoryIds?: string[];
  brandId?: string | null;
  expirationDate?: string | null;
  unitWeightKg?: number;
  minPurchaseQty?: number;
  aiAssisted?: boolean;
}

/** Fields a product update may set. Undefined = leave unchanged. */
export type ProductPatch = Partial<NewProduct>;

export interface ProductSearchCriteria {
  q?: string;
  limit: number;
  offset: number;
  activeOnly: boolean;
  brandSlug?: string;
  categorySlug?: string;
}
