/**
 * The warehouse module's data shapes.
 *
 * Purchase cost and stock value are nullable on purpose: the server leaves them
 * out of the payload for anyone without stock.view_costs, so the interface can
 * tell "no cost recorded" from "not yours to see".
 */
export type ProductStockStatus = 'ok' | 'low' | 'out';

export type ProductCategoryRef = {
    id: number;
    name: string;
    code: string | null;
};

export type ProductVerification = {
    value: string;
    label: string;
    tone: string;
};

export type ProductSummary = {
    id: number;
    sku: string;
    name: string;
    brand: string | null;
    model_number: string | null;
    unit: string;
    unit_label: string;
    category: ProductCategoryRef | null;
    physical_quantity: number;
    reserved_quantity: number;
    damaged_quantity: number;
    available_quantity: number;
    minimum_stock: number;
    reorder_quantity: number;
    stock_status: ProductStockStatus;
    storage_location: string | null;
    verification: ProductVerification;
    is_active: boolean;
    purchase_cost: string | null;
    stock_value: number | null;
};

export type InventoryRow = ProductSummary & {
    shortfall: number;
    suggested_order_quantity: number;
};

export type ProductSupplier = {
    id: number;
    name: string;
    contact_name: string | null;
    email: string | null;
    phone: string | null;
    website: string | null;
    lead_time_days: number | null;
    is_active: boolean;
    product_code: string | null;
    product_url: string | null;
    unit_cost: string | null;
    pivot_lead_time_days: number | null;
    is_preferred: boolean;
};

export type ProductDetail = ProductSummary & {
    description: string | null;
    manufacturer: string | null;
    specifications: Array<{ label: string; value: string }>;
    packaging_quantity: number;
    gst_treatment: { value: string; label: string };
    tracks_serial_numbers: boolean;
    tracks_batches: boolean;
    warranty_months: number | null;
    datasheet_url: string | null;
    source_url: string | null;
    source_reviewed_on: string | null;
    verification_description: string;
    created_at: string | null;
    updated_at: string | null;
    updated_by: string | null;
    suppliers: ProductSupplier[];
};

export type StockMovementRow = {
    id: number;
    type: { value: string; label: string };
    bucket: string;
    quantity: number;
    balance_after: number;
    reason: string | null;
    reference: string | null;
    job: { id: number; job_number: string } | null;
    user: string | null;
    occurred_at: string;
    product?: {
        id: number;
        sku: string;
        name: string;
        unit: string;
    };
};

export type WarehouseAbilities = {
    viewCosts: boolean;
    manage: boolean;
    adjust: boolean;
    manageSuppliers: boolean;
};

export type ProductCategoryRow = {
    id: number;
    name: string;
    code: string | null;
    description: string | null;
    parent_id: number | null;
    sort_order: number;
    is_active: boolean;
    products_count: number;
};

export type SupplierRow = {
    id: number;
    name: string;
    contact_name: string | null;
    email: string | null;
    phone: string | null;
    website: string | null;
    account_reference: string | null;
    catalogue_url: string | null;
    lead_time_days: number | null;
    notes: string | null;
    is_active: boolean;
    products_count: number;
};

export type ProductFormOptions = {
    categories: Array<{ value: number; label: string }>;
    units: Array<{ value: string; label: string }>;
    verifications: Array<{ value: string; label: string; description: string }>;
    gstTreatments: Array<{ value: string; label: string; description: string }>;
};
