import { Area } from '@/types/api/master-data/area';
import { Flock } from '@/types/api/master-data/flock';
import { Kandang } from '@/types/api/master-data/kandang';
import { Location } from '@/types/api/master-data/location';
import { BaseApproval, BaseMetadata } from '@/types/api/api-general';
import { Nonstock } from '@/types/api/master-data/nonstock';
import { ProductionStandard } from '@/types/api/master-data/production-standard';
import { Warehouse } from '@/types/api/master-data/warehouse';

export type BaseProjectFlock = {
  id: number;
  name?: string;
  flock_name?: string;
  status: string;
  area: Area;
  area_id: number;
  category: string;
  production_standard: ProductionStandard;
  production_standard_id: number;
  location: Location;
  location_id: number;
  period: number;
  kandang_ids: number[];
  kandangs: (Kandang & {
    project_flock_kandang_id: number;
    closed_at?: string;
  })[];
  project_budgets?: ProjectFlockBudget[];
  approval: BaseApproval;
};

export type PeriodFlock = {
  flock: Flock;
  next_period: number;
};

export type ProjectFlockBudget = {
  id?: number;
  project_flock_id?: number;
  nonstock_id: number;
  nonstock?: Nonstock;
  qty: number;
  price: number;
};

export type ProjectFlock = BaseMetadata & BaseProjectFlock;

export type CreateProjectFlockPayload = {
  flock_name: string;
  area_id: number;
  category: string;
  production_standard_id: number;
  location_id: number;
  periode: number;
  kandang_ids: number[];
  project_budgets?: ProjectFlockBudget[];
};

export type UpdateProjectFlockPayload = CreateProjectFlockPayload;

export type ProjectFlockApprovalPayload = {
  action: 'APPROVED' | 'REJECTED';
  approvable_ids: number[];
};

export type ProjectFlockKandangLookup = {
  id: number;
  project_flock_kandang_id: number;
  project_flock_id: number;
  kandang_id: number;
  kandang: Kandang;
  project_flock: ProjectFlock;
  warehouse: Warehouse;
  quantity: number;
  available_quantity?: number;
  population: number;
  chick_in_date: string;
  is_transition: boolean;
  is_laying: boolean;
};

export type ProjectFlockAvailableQuantity = {
  project_flock_id: number;
  flock_name: string;
  category: 'LAYING' | 'GROWING';
  kandangs: {
    project_flock_kandang_id: number;
    available_qty: number;
  }[];
};

export type ProjectFlockMaxQuantity = {
  project_flock_id: number;
  project_flock_kandangs: {
    project_flock_kandang_id: number;
    max_target_qty: number;
  }[];
};

export type ProjectFlockPeriods = {
  id: number;
  name: string;
  period: number;
}[];
