export interface DiscountPromoOption {
  id: number;
  code: string;
  description: string;
  privateDescription: string;
  dateStart: string | null;
  dateEnd: string | null;
  usageCount: number;
}

export type DiscountPromoType = 'none' | 'percentage_subtotal' | 'percentage_regular' | 'fixed_amount';
export type ShippingPromoType = 'none' | 'percentage' | 'fixed';
export type ShippingTierMode = 'percentage' | 'flat';

export interface ShippingTierConfig {
  threshold: number;
  mode: ShippingTierMode;
  value: number;
  id?: string;
}

export type SurchargeTarget = 'shipping' | 'order';

export interface SurchargeConfig {
  threshold: number;
  maxThreshold?: number;
  target: SurchargeTarget;
  amount: number;
  id?: string;
}

export interface DiscountSimulationBucket {
  key: string;
  label: string;
  min: number;
  max: number | null;
  orderCount: number;
  weight: number;
  orderValue: number;
  productDiscountAmount: number;
  promoProductDiscount: number;
  customerItemCost: number;
  shippingChargeBase: number;
  shippingAfterAuto: number;
  shipPromoDiscount: number;
  shippingSurcharge: number;
  orderSurcharge: number;
  customerShipCost: number;
  actualShippingCost: number;
  totalRevenue: number;
  productCogs: number;
  merchantFees: number;
  pointsCost: number;
  fixedCosts: number;
  totalCosts: number;
  profit: number;
  profitPercent: number;
}

export interface DiscountSimulationTotals {
  orders: number;
  subtotal: number;
  productDiscountRate: number;
  pointsPerDollar: number;
  redemptionRate: number;
  pointDollarValue: number;
  weightedProfitAmount: number;
  weightedProfitPercent: number;
  overallCogsPercentage?: number;
}

export interface DiscountSimulationResponse {
  dateRange: {
    start: string;
    end: string;
  };
  totals: DiscountSimulationTotals;
  buckets: DiscountSimulationBucket[];
}

export type CogsCalculationMode = 'actual' | 'average';

export interface DiscountSimulationRequest {
  dateRange: {
    start: string;
    end: string;
  };
  filters: {
    shipCountry?: string;
    promoIds?: Array<number | string>;
    promoCodes?: string[];
  };
  productPromo: {
    type: DiscountPromoType;
    value: number;
    minSubtotal: number;
  };
  shippingPromo: {
    type: ShippingPromoType;
    value: number;
    minSubtotal: number;
    maxDiscount: number;
  };
  shippingTiers: ShippingTierConfig[];
  surcharges: SurchargeConfig[];
  merchantFeePercent: number;
  fixedCostPerOrder: number;
  cogsCalculationMode: CogsCalculationMode;
  applyHistoricalProductPromo: boolean;
  pointsConfig: {
    pointsPerDollar: number | null;
    redemptionRate: number | null;
    pointDollarValue: number | null;
  };
}
