import type { Paginated } from '@/types/common';
import type { MediaItem, MediaUploadState } from '@/types/media';

export const PRICE_TYPES = [
    'distributor',
    'agent',
    'sub_agent',
    'grosir',
    'retail',
    'tiktok',
    'shopee',
    'harga_modal',
] as const;

export type PriceType = (typeof PRICE_TYPES)[number];

export const PRICE_TYPE_LABELS: Record<PriceType, string> = {
    distributor: 'Distributor',
    agent: 'Agen',
    sub_agent: 'Sub Agen',
    grosir: 'Grosir',
    retail: 'Eceran',
    tiktok: 'TikTok',
    shopee: 'Shopee',
    harga_modal: 'Harga Modal',
};

export interface Price {
    id: number;
    variant_id: number;
    type: string;
    price: number;
    price_formatted: string;
    price_input?: string;
    type_label: string;
}

export interface Variant {
    id: number;
    product_id: number;
    name: string;
    stock: number;
    stock_formatted: string;
    reject_stock: number;
    reject_stock_formatted: string;
    retail_stock: number;
    retail_stock_formatted: string;
    prices: Price[];
    images: MediaItem[];
}

export type ProductPriceItem = Price;
export type ProductVariantItem = Variant;

export interface Category {
    id: number;
    name: string;
    slug: string;
}

export interface Product {
    id: number;
    name: string;
    slug: string;
    description: string | null;
    is_active: boolean;
    categories: Category[];
    variants: Variant[];
}

export interface ProductListItem extends Product {
    total_stock_formatted?: string;
    total_reject_stock_formatted?: string;
    total_retail_stock_formatted?: string;
    has_pending_request?: boolean;
    pending_request_id?: number;
    pending_request_action?: string;
    pending_request_action_label?: string;
    display_is_active?: boolean;
}

export interface CategoryOption {
    value: number;
    label: string;
}

export type PaginatedProducts = Paginated<ProductListItem>;

export interface ProductVariantFormItem {
    client_id: string;
    id?: number;
    name: string;
    stock: string | number;
    retail_stock: string | number;
    media: MediaUploadState;
    [key: string]: unknown;
}

export type ProductFormInitialData = {
    name?: string;
    description?: string;
    category_ids?: number[];
    variants?: Array<{
        id?: number;
        name?: string;
        stock?: number | string;
        retail_stock?: number | string;
        images?: MediaItem[];
    }>;
};
