import type { MediaItem } from '@/types/media';
import type { Paginated } from '@/types/common';
import type { ProductListItem } from '@/types/product';
import type { RawMaterialListItem } from '@/types/raw-material';

export type CuttingStatusAction = {
    status: string;
    label: string;
    destructive: boolean;
    permission: string;
    icon_only: boolean;
};

export type CuttingMaterialListItem = {
    id: number;
    material_usage_formatted: string;
    variant?: string;
    raw_material_id?: number;
    raw_material_name?: string;
    raw_material_unit_label?: string;
    raw_material_price?: {
        id: number;
        variant: string;
        raw_material?: {
            id: number;
            name: string;
            unit?: string;
            unit_label?: string;
            unit_abbreviation?: string;
        };
    };
};

export type CuttingResultPriceItem = {
    id: number;
    product_variant_id: number;
    price_type: string;
    price: number;
    price_formatted: string;
    cost_per_unit: number;
    cost_per_unit_formatted: string;
    type_label: string;
};

export type CuttingResultListItem = {
    id: number;
    cutting_result: number;
    sample: number;
    original_outside_sample: number;
    product_variant?: {
        id: number;
        name: string;
        product?: {
            id: number;
            name: string;
        };
    };
};

export type CuttingListItem = {
    id: number;
    status: string;
    status_label: string;
    description: string | null;
    is_editable: boolean;
    available_actions: CuttingStatusAction[];
    created_at_formatted: string;
    total_material_cost?: number;
    total_material_cost_formatted?: string;
    sewing_cost?: number;
    sewing_cost_formatted?: string;
    other_cost?: number;
    other_cost_formatted?: string;
    total_production_cost?: number;
    total_production_cost_formatted?: string;
    total_result_pieces?: number;
    total_material_usage?: number;
    total_material_usage_summary_formatted?: string;
    estimated_cost_per_unit?: number;
    estimated_cost_per_unit_formatted?: string;
    created_by?: {
        username: string;
        profile?: {
            full_name: string;
        };
    };
    submitted_by?: {
        username: string;
        profile?: {
            full_name: string;
        };
    };
    rejection?: {
        reason: string;
        rejected_by?: {
            profile?: {
                full_name: string;
            };
        };
    } | null;
    materials: CuttingMaterialListItem[];
    results: CuttingResultListItem[];
    result_prices?: CuttingResultPriceItem[];
};

export type CuttingMaterialCartItem = {
    raw_material_price_id: number;
    raw_material_name: string;
    variant: string;
    unit: string;
    unit_abbreviation: string;
    stock_input: string;
    material_usage: string;
    images?: MediaItem[];
};

export type CuttingResultCartItem = {
    product_variant_id: number;
    product_name: string;
    variant_name: string;
    stock: number;
    cutting_result: string;
    sample: string;
    original_outside_sample: string;
    images?: MediaItem[];
};

export type CuttingEditItem = {
    id: number;
    status: string;
    description: string | null;
    sewing_cost?: number;
    other_cost?: number;
    materials: Array<{
        raw_material_price_id: number;
        material_usage_input: string;
        variant?: string;
        stock_input?: string;
        images?: MediaItem[];
        unit?: string;
        unit_abbreviation?: string;
        raw_material_name?: string;
        raw_material_price?: {
            variant: string;
            stock_input?: string;
            images?: MediaItem[];
            raw_material?: {
                name: string;
                unit?: string;
                unit_abbreviation?: string;
            };
        };
    }>;
    results: Array<{
        product_variant_id: number;
        cutting_result: number;
        sample: number;
        original_outside_sample: number;
        product_variant?: {
            name: string;
            stock: number;
            images?: MediaItem[];
            product?: {
                name: string;
            };
        };
    }>;
};

export type PaginatedCuttings = Paginated<CuttingListItem>;

export type CuttingRawMaterialCatalogItem = RawMaterialListItem;
export type CuttingProductCatalogItem = ProductListItem;
