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 ProfitLossAnalyticSummary summary,
    required List<ProfitLossAnalyticItem> data,
    required List<ProfitLossAnalyticProduct> productData,
  }) = _ProfitLossAnalytic;

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

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

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

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

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

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

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