import { Kandang } from '@/type/master-data/kandang';
import { ProjectFlock } from '@/types/api/production/project-flock';
import { ProductWarehouse } from '@/types/api/inventory/product-warehouse';
import { BaseApproval } from '@/types/api/api-general';

export type BaseProjectFlockKandang = {
  id: number;
  project_flock_id: number;
  kandang_id: number;
  kandang: Kandang;
  project_flock: ProjectFlock;
  name_with_period?: string;
  approval: BaseApproval;
  chickins?: Chickin[];
  available_qtys?: AvailableQty[];
  chickin_approval?: BaseApproval;
};

export type AvailableQty = {
  chick_in_date?: string;
  available_qty: number;
  product_warehouse: ProductWarehouse;
  note?: string;
};

export type Chickin = {
  id: number;
  project_flock_kandang_id: number;
  chick_in_date: string;
  product_warehouse_id: number;
  product_warehouse: ProductWarehouse;
  usage_qty: number;
  pending_usage_qty: number;
  note: string;
};

export type ProjectFlockKandang = BaseProjectFlockKandang;

export type LookupProjectFlockKandangPayload = {
  project_flock_id: number;
  kandang_id: number;
};

export type ClosingProjectFlockKandangPayload = {
  action: 'close' | 'unclose';
  closed_date?: string; // YYYY-MM-DD, DD-MM-YYYY, or RFC3339
};

export type ClosingExpense = {
  id: number;
  po_number: string;
  category: string;
  total: number;
  status: string;
  step_name: string;
  step: number;
  reference_number: string;
};

export type StockItem = {
  flag_name: string;
  product_warehouse_id: number;
  product_id: number;
  product_name: string;
  product_category: string;
  uom: string;
  quantity: number;
};

export type CheckClosingResponse = {
  unfinished_expenses: number;
  stock_remaining: StockItem[];
  expenses: ClosingExpense[];
};
