part of '../analytic.dart';

@freezed
class ProfitLossAnalytic with _$ProfitLossAnalytic {
  const factory ProfitLossAnalytic({
    required String organizationId,
    required String dateFrom,
    required String dateTo,
    required String groupBy,
    required ProfitLossSummary summary,
    required List<ProfitLossDailyData> data,
    required List<ProfitLossProductData> productData,
  }) = _ProfitLossAnalytic;

  factory ProfitLossAnalytic.empty() => ProfitLossAnalytic(
    organizationId: '',
    dateFrom: '',
    dateTo: '',
    groupBy: '',
    summary: ProfitLossSummary.empty(),
    data: [],
    productData: [],
  );
}

@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,
  );
}
