import { BaseApproval, CreatedUser } from '@/types/api/api-general';
import { Supplier } from '@/types/api/master-data/supplier';
import { Nonstock } from '@/types/api/master-data/nonstock';
import { Kandang } from '@/types/api/master-data/kandang';

export type Pengajuan = {
  id: number;
  expense_id: number;
  project_flock_kandang_id: number;
  kandang_id: number;
  nonstock_id: number;
  qty: number;
  price: number;
  notes: string;
  nonstock: Nonstock;
  created_at: string;
};

export type Realisasi = {
  id: number;
  expense_nonstock_id: number;
  qty: number;
  price: number;
  notes: string;
  nonstock: Nonstock;
  created_at: string;
};

export type ReportExpense = {
  id: number;
  reference_number: string;
  po_number: string;
  category: string;
  supplier: Supplier;
  realization_date: string;
  transaction_date: string;
  pengajuan: Pengajuan;
  realisasi: Realisasi;
  kandang: Kandang;
  created_at: string;
  updated_at: string;
  created_user: CreatedUser;
  latest_approval: BaseApproval;
};

export type ReportExpenseSearchParams = {
  locationId: string | null;
  supplierId: string | null;
  kandangId: string | null;
  nonstockId: string | null;
  realizationDate: string | null;
  category: string | null;
  search: string;
};

export type ReportDepreciation = {
  project_flock_id: number;
  farm_name: string;
  period: string;
  depreciation_percent_effective: number;
  depreciation_value: number;
  pullet_cost_day_n_total: number;
  hpp?: number;
  components: {
    kandang: {
      kandang_id: number;
      hpp?: number;
      transfer_id: number;
      cutover_date: string;
      kandang_name: string;
      manual_input_id: number;
      depreciation_value: number;
      start_schedule_day: number;
      depreciation_percent: number;
      source_project_flock_id: number;
      day_n: number;
      transfer_date: string;
      pullet_cost_day_n: number;
      depreciation_source: string;
      project_flock_kandang_id: number;
      transfer_qty: number;
      house_type: string;
      origin_date: string;
    }[];
    kandang_count: number;
  };
};

export type ReportDepreciationSearchParams = {
  farm: string | null;
  period: string | null;
};

export type ReportDepreciationV2KandangItem = {
  kandang_id: number;
  kandang_name: string;
  transfer_id: number;
  depreciation_percent: number;
  pullet_cost_day_n: number;
  depreciation_value: number;
  chickin_date: string;
  project_flock_kandang_id: number;
  depreciation_source: string;
  transfer_date: string;
  source_project_flock_id: number;
  house_type: string;
  multiplication_percentage: number;
  cutover_date: string;
  origin_date: string;
  standard_effective_date: string;
  population: number;
  transfer_qty: number;
  total_value_pullet_after_depreciation: number;
  manual_input_id: number;
  start_schedule_day: number;
  day_n: number;
};

export type ReportDepreciationV2Item = {
  date: string;
  depreciation_percent_effective: number;
  depreciation_value: number;
  pullet_cost_day_n_total: number;
  multiplication_percentage: number;
  day_n: number;
  chickin_date: string;
  total_value_pullet_after_depreciation: number;
  standard_effective_date: string;
  total_population: number;
  components: {
    kandang_count: number;
    total_population: number;
    kandang: ReportDepreciationV2KandangItem[];
  };
};

export type DepreciationV2Meta = {
  project_flock_id: number;
  farm_name: string;
  location_id: number;
  period: string;
  limit: number;
  total_days: number;
};

export type DepreciationV2Response = {
  code: number;
  status: string;
  message: string;
  meta: DepreciationV2Meta;
  data: ReportDepreciationV2Item[];
};
