part of '../analytic.dart';

@freezed
class ProfitLossAnalytic with _$ProfitLossAnalytic {
  const factory ProfitLossAnalytic({
    required String organizationId,
    required String outletId,
    required String outletName,
    required String dateFrom,
    required String dateTo,
    required String groupBy,
    required ProfitLossSummary summary,
    required List<ProfitLossDailyData> data,
    required List<ProfitLossProductData> productData,
    required List<ProfitLossMainSummaryItem> mainSummary,
    required ProfitLossPurchasing purchasing,
    required List<ProfitLossOperationalExpense> operationalExpenses,
    required int operationalExpensesTotal,
  }) = _ProfitLossAnalytic;

  factory ProfitLossAnalytic.empty() => ProfitLossAnalytic(
    organizationId: '',
    outletId: '',
    outletName: '',
    dateFrom: '',
    dateTo: '',
    groupBy: '',
    summary: ProfitLossSummary.empty(),
    data: [],
    productData: [],
    mainSummary: [],
    purchasing: ProfitLossPurchasing.empty(),
    operationalExpenses: [],
    operationalExpensesTotal: 0,
  );
}

@freezed
class ProfitLossSummary with _$ProfitLossSummary {
  const factory ProfitLossSummary({
    required int totalRevenue,
    required int totalCost,
    required int grossProfit,
    required double grossProfitMargin,
    required int totalTax,
    required int totalDiscount,
    required int netProfit,
    required double netProfitMargin,
    required int totalOrders,
    required double averageProfit,
    required double profitabilityRatio,
  }) = _ProfitLossSummary;

  factory ProfitLossSummary.empty() => ProfitLossSummary(
    totalRevenue: 0,
    totalCost: 0,
    grossProfit: 0,
    grossProfitMargin: 0,
    totalTax: 0,
    totalDiscount: 0,
    netProfit: 0,
    netProfitMargin: 0,
    totalOrders: 0,
    averageProfit: 0,
    profitabilityRatio: 0,
  );
}

@freezed
class ProfitLossDailyData with _$ProfitLossDailyData {
  const factory ProfitLossDailyData({
    required String date,
    required int revenue,
    required int cost,
    required int grossProfit,
    required double grossProfitMargin,
    required int tax,
    required int discount,
    required int netProfit,
    required double netProfitMargin,
    required int orders,
  }) = _ProfitLossDailyData;

  factory ProfitLossDailyData.empty() => ProfitLossDailyData(
    date: '',
    revenue: 0,
    cost: 0,
    grossProfit: 0,
    grossProfitMargin: 0,
    tax: 0,
    discount: 0,
    netProfit: 0,
    netProfitMargin: 0,
    orders: 0,
  );
}

@freezed
class ProfitLossProductData with _$ProfitLossProductData {
  const factory ProfitLossProductData({
    required String productId,
    required String productName,
    required String categoryId,
    required String categoryName,
    required int quantitySold,
    required int revenue,
    required int cost,
    required int grossProfit,
    required double grossProfitMargin,
    required int averagePrice,
    required int averageCost,
    required int profitPerUnit,
  }) = _ProfitLossProductData;

  factory ProfitLossProductData.empty() => ProfitLossProductData(
    productId: '',
    productName: '',
    categoryId: '',
    categoryName: '',
    quantitySold: 0,
    revenue: 0,
    cost: 0,
    grossProfit: 0,
    grossProfitMargin: 0,
    averagePrice: 0,
    averageCost: 0,
    profitPerUnit: 0,
  );
}

@freezed
class ProfitLossMainSummaryItem with _$ProfitLossMainSummaryItem {
  const factory ProfitLossMainSummaryItem({
    required String id,
    required String label,
    required bool isBold,
    required int todayNominal,
    required double todayPct,
    required int mtdNominal,
    required double mtdPct,
    @Default([]) List<ProfitLossMainSummaryItem> subItems,
  }) = _ProfitLossMainSummaryItem;

  factory ProfitLossMainSummaryItem.empty() => const ProfitLossMainSummaryItem(
    id: '',
    label: '',
    isBold: false,
    todayNominal: 0,
    todayPct: 0,
    mtdNominal: 0,
    mtdPct: 0,
    subItems: [],
  );
}

@freezed
class ProfitLossPurchasing with _$ProfitLossPurchasing {
  const factory ProfitLossPurchasing({
    required int todayTotal,
    required int mtdTotal,
    required int todayRawMaterial,
    required int mtdRawMaterial,
    required int todayExpense,
    required int mtdExpense,
    @Default([]) List<ProfitLossPurchasingItem> items,
  }) = _ProfitLossPurchasing;

  factory ProfitLossPurchasing.empty() => const ProfitLossPurchasing(
    todayTotal: 0,
    mtdTotal: 0,
    todayRawMaterial: 0,
    mtdRawMaterial: 0,
    todayExpense: 0,
    mtdExpense: 0,
    items: [],
  );
}

@freezed
class ProfitLossPurchasingItem with _$ProfitLossPurchasingItem {
  const factory ProfitLossPurchasingItem({
    required String date,
    required String item,
    required int quantity,
    required int nominal,
  }) = _ProfitLossPurchasingItem;

  factory ProfitLossPurchasingItem.empty() => const ProfitLossPurchasingItem(
    date: '',
    item: '',
    quantity: 0,
    nominal: 0,
  );
}

@freezed
class ProfitLossOperationalExpense with _$ProfitLossOperationalExpense {
  const factory ProfitLossOperationalExpense({
    required String item,
    required int nominal,
  }) = _ProfitLossOperationalExpense;

  factory ProfitLossOperationalExpense.empty() =>
      const ProfitLossOperationalExpense(item: '', nominal: 0);
}
