import type { Paginated } from '@/types/common';
import type { MediaItem } from '@/types/media';
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;
    material_result?: number | null;
    combination_material_result?: number | null;
    variant?: string;
    raw_material_id?: number;
    raw_material_name?: string;
    raw_material_unit_label?: string;
    images?: MediaItem[];
    combination_id?: number | null;
    raw_material_price?: {
        id: number;
        variant: string;
        images?: MediaItem[];
        raw_material?: {
            id: number;
            name: string;
            unit?: string;
            unit_label?: string;
            unit_abbreviation?: string;
        };
    };
};

export type CuttingResultListItem = {
    id: number;
    cutting_result: number;
    sample: number;
    original_outside_sample: number;
    product_name?: string;
};

export type CuttingListItem = {
    id: number;
    status: string;
    status_label: string;
    description: string | null;
    images?: MediaItem[];
    is_editable: boolean;
    available_actions: CuttingStatusAction[];
    created_at_formatted: string;
    total_material_cost?: number;
    total_material_cost_formatted?: string;
    material_cost_per_product?: number;
    material_cost_per_product_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[];
};

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;
    material_result?: string | null;
    images?: MediaItem[];
    combination_id?: number | null;
    combination_material_result?: number | null;
};

export type CuttingResultCartItem = {
    product_name: string;
    cutting_result: string | null;
    sample: string | null;
    original_outside_sample: string | null;
};

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

export type PaginatedCuttings = Paginated<CuttingListItem>;

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