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

export type RestockProductCatalogItem = ProductListItem & {
    variants: Array<ProductListItem['variants'][number] & {
        harga_modal: number;
    }>;
};

export type RestockItemListItem = {
    id: number;
    product_name: string;
    variant_name: string;
    quantity_formatted: string;
    unit_price_formatted: string;
    subtotal_formatted: string;
};

export type RestockItemDetail = RestockItemListItem & {
    product_variant_id?: number;
    product_variant?: {
        id: number;
        name: string;
        stock?: number;
        product?: {
            id: number;
            name: string;
        };
    };
};

export type RestockListItem = {
    id: number;
    stock_type: string;
    stock_type_label: string;
    subtotal_formatted: string;
    total_formatted: string;
    notes: string | null;
    created_at_formatted: string;
    created_by_name?: string;
    created_by?: {
        username: string;
        profile?: {
            full_name: string;
        } | null;
    } | null;
    photos?: MediaItem | null;
    items: RestockItemDetail[];
    has_pending_request?: boolean;
    pending_request_id?: number;
    pending_request_action?: string;
    pending_request_action_label?: string;
    pending_request_submitted_by_name?: string;
};

export type RestockCartItem = {
    product_variant_id: number;
    product_name: string;
    variant_name: string;
    stock: number;
    quantity: string;
    unit_price: number;
    images?: MediaItem[];
};

export type RestockFormData = {
    notes: string;
    photos: File[];
    remove_media_ids: number[];
    items: RestockCartItem[];
};

export type RestockEditItem = {
    id: number;
    notes: string | null;
    stock_type: string;
    photos?: MediaItem | null;
    items: Array<{
        product_variant_id: number;
        product_name: string;
        variant_name: string;
        quantity_input: string;
        unit_price: number;
        stock?: number;
        product_variant?: {
            images?: MediaItem[];
        };
    }>;
};

export type PaginatedRestocks = Paginated<RestockListItem>;
