import { BaseApiResponse, BaseMetadata } from '@/types/api/api-general';
import { BaseCustomer } from '@/types/api/master-data/customer';
import {
  BaseWarehouseArea,
  BaseWarehouseKandang,
  BaseWarehouseLocation,
} from '@/types/api/master-data/warehouse';
import { BaseProduct } from '@/types/api/master-data/product';
import { BaseUser } from '@/types/api/user';

export type BaseDailyMarketingRow = {
  id: number;
  so_date: string;
  realization_date: string;
  aging_days: number;

  warehouse: BaseWarehouseArea | BaseWarehouseLocation | BaseWarehouseKandang;
  customer: BaseCustomer;
  sales: BaseUser;
  product: BaseProduct;

  do_number: string;
  vehicle_number: string;
  marketing_type: string;

  qty: number;
  average_weight_kg: number;
  total_weight_kg: number;

  sales_price_per_kg: number;
  hpp_price_per_kg: number;

  sales_amount: number;
  hpp_amount: number;
};

export type DailyMarketingRow = BaseMetadata & BaseDailyMarketingRow;

export interface SalesSummary {
  total_qty: number;
  average_weight_kg: number;
  total_weight_kg: number;
  average_sales_price: number;
  total_sales_amount: number;
  total_hpp_amount: number;
  total_hpp_price_per_kg: number;
}

export type DailyMarketingReport = DailyMarketingRow[];

export type DailyMarketingReportResponse =
  BaseApiResponse<DailyMarketingReport> & { total: SalesSummary };

export type MarketingReportFilters = {
  area_id?: number;
  location_id?: number;
  warehouse_id?: number;
  customer_id?: number;
  start_date?: string;
  end_date?: string;
  date_type?: 'realized' | 'transaction';
};
