import { ApiPaginatedResponse } from '../api-paginated-response.interface';

export interface Product {
  id: number;
  category_id: number;
  brand_id: number | null;
  slug: string;
  nombre: string;
  descripcion: string;
  precio: string;
  category: string;
  brand: string | null;
  images: string[];
}

export interface ProductAttributeOption {
  id: number;
  value: string;
  label: string;
  sort_order: number;
  metadata: Record<string, unknown> | null;
}

export interface ProductAttribute {
  id: number;
  codigo: string;
  nombre: string;
  is_required: boolean;
  metadata_schema: Record<string, unknown> | null;
  type: string;
  options: ProductAttributeOption[];
}

export type InventoryPolicy = 'tracked' | 'unlimited';

export interface CatalogItemVariant {
  id: number;
  stock_tecnico: number | null;
  minimum_use_date?: string | null;
  maximum_use_date?: string | null;
  effective_minimum_use_date?: string | null;
  effective_maximum_use_date?: string | null;
  values: Record<string, string>;
}

export interface SelectedCatalogItemVariant extends CatalogItemVariant {
  images: string[];
}

export interface CatalogItemDetail {
  id: number;
  category_id: number | null;
  brand_id: number | null;
  slug: string;
  nombre: string;
  descripcion: string | null;
  precio: string;
  category: string | null;
  brand: string | null;
  inventory_policy: InventoryPolicy;
  has_tickets: boolean;
  minimum_use_date: string | null;
  maximum_use_date: string | null;
  attributes: ProductAttribute[];
  variants: CatalogItemVariant[];
  selected_variant?: SelectedCatalogItemVariant;
  stock_tecnico?: number | null;
  images?: string[];
}

export type CatalogProductLayout = 'row' | 'column_with_image' | 'column_with_cart';
export type CatalogGroupLayout = 'paginated' | 'simple' | 'simple_vertical' | 'carousel';

export interface CatalogFeaturedItemVariant {
  id: number;
  stock_tecnico: number | null;
  values: Record<string, string>;
}

export interface CatalogFeaturedItem {
  id: number;
  nombre: string;
  descripcion?: string | null;
  precio: number | string;
  image?: string | null;
  stock_tecnico?: number | null;
  variants?: CatalogFeaturedItemVariant[];
}

export type CatalogFeaturedItems =
  | ApiPaginatedResponse<CatalogFeaturedItem[]>
  | CatalogFeaturedItem[];

export interface CatalogFeaturedGroup {
  id: number;
  title: string;
  layout: CatalogProductLayout;
  group_layout: CatalogGroupLayout;
  group_order: number;
  items: CatalogFeaturedItems;
}

export interface CatalogCategory {
  id: number;
  nombre: string;
  categoria_id: number | null;
}

export interface CategoryItemsResponse extends ApiPaginatedResponse<CatalogFeaturedItem[]> {
  category: CatalogCategory;
  layout: CatalogProductLayout;
  group_layout: CatalogGroupLayout;
}
