import type { Paginated } from '@/types/common';

export type StokOpnameStatus = 'draft' | 'pending' | 'verified' | 'rejected';

export type StokOpnameListItem = {
    id: number;
    opname_date: string;
    opname_date_formatted: string;
    status: StokOpnameStatus;
    status_label: string;
    notes: string | null;
    verification_notes: string | null;
    created_by_name: string;
    created_at_formatted: string;
    items_count: number;
    items_with_difference_count: number;
};

export type StokOpnameItem = {
    id: number;
    product_variant_id: number;
    variant_name: string;
    product_name: string;
    system_stock: number;
    physical_stock: number;
    difference: number;
    notes: string | null;
};

export type StokOpnameDetail = {
    id: number;
    opname_date: string;
    status: StokOpnameStatus;
    status_label: string;
    notes: string | null;
    verification_notes: string | null;
    created_by_name: string;
    created_at_formatted: string;
    items: StokOpnameItem[];
};

export type StokOpnameFormData = {
    opname_date: string;
    notes: string;
    items: Array<{
        product_variant_id: number;
        physical_stock: number;
        notes: string;
    }>;
};

export type CatalogVariant = {
    id: number;
    name: string;
    stock: number;
    stock_formatted?: string;
};

export type CatalogProduct = {
    id: number;
    name: string;
    variants: CatalogVariant[];
};

export type PaginatedStokOpnames = Paginated<StokOpnameListItem>;

export type StokOpnameVariantRow = {
    product_name: string;
    variant_id: number;
    variant_name: string;
    system_stock: number;
    system_stock_formatted?: string;
    physical_stock: number;
    notes: string;
};

export type StokOpnameProductGroup = {
    product_name: string;
    rows: StokOpnameVariantRow[];
    startIndex: number;
};

export type StokOpnameExistingItem = {
    product_variant_id: number;
    physical_stock: number;
    notes: string | null;
};
