import {
  BaseApproval,
  BaseMetadata,
  CreatedUser,
} from '@/types/api/api-general';
import { BaseKandang } from '@/types/api/master-data/kandang';
import { WarehouseType } from '@/types/api/master-data/warehouse';

export type BaseTransferToLaying = {
  id: number;
  transfer_number: string;
  transfer_date: string;
  notes: string;
  from_project_flock: {
    id: number;
    flock_name: string;
    category: 'GROWING' | 'LAYING';
  };
  to_project_flock: {
    id: number;
    flock_name: string;
    category: 'GROWING' | 'LAYING';
  };
  pending_usage_qty: number | null;
  usage_qty: number | null;

  sources: {
    source_project_flock_kandang: {
      id: number;
      kandang: Omit<BaseKandang, 'status' | 'location' | 'pic'>;
    };
    qty: number;
    product_warehouse: {
      id: number;
      product_id: number;
      warehouse_id: number;
      quantity: number;
      product: {
        id: number;
        name: string;
      };
      warehouse: {
        id: number;
        name: string;
        type: WarehouseType;
      };
    };
  }[];

  targets: {
    target_project_flock_kandang: {
      id: number;
      kandang: Omit<BaseKandang, 'status' | 'location' | 'pic'>;
    };
    qty: number;
    product_warehouse: {
      product: {
        id: number;
        name: string;
      };
      warehouse: {
        id: number;
        name: string;
        type: WarehouseType;
      };
    };
  }[];

  created_by: number;
  created_user: CreatedUser;
  created_at: string;

  approval: BaseApproval;
};

export type TransferToLaying = BaseMetadata & BaseTransferToLaying;

export type CreateTransferToLayingPayload = {
  transfer_date: string;
  source_project_flock_id: number;
  target_project_flock_id: number;
  totalQuantity: number;
  source_kandangs: {
    project_flock_kandang_id: number;
    quantity: number;
  }[];
  target_kandangs: {
    project_flock_kandang_id: number;
    quantity: number;
  }[];
  reason: string;
};

export type UpdateTransferToLayingPayload = CreateTransferToLayingPayload;

export type TransferToLayingFilter = {
  flockSource: number[];
  flockDestination: number[];
  status: number[];
  startDate: string;
  endDate: string;
};
