part of '../analytic_dtos.dart';

@freezed
class ProductAnalyticDto with _$ProductAnalyticDto {
  const ProductAnalyticDto._();

  const factory ProductAnalyticDto({
    @JsonKey(name: 'organization_id') required String organizationId,
    @JsonKey(name: 'outlet_id') required String outletId,
    @JsonKey(name: 'date_from') required String dateFrom,
    @JsonKey(name: 'date_to') required String dateTo,
    required List<ProductAnalyticDataDto> data,
  }) = _ProductAnalyticDto;

  factory ProductAnalyticDto.fromJson(Map<String, dynamic> json) =>
      _$ProductAnalyticDtoFromJson(json);

  ProductAnalytic toDomain() => ProductAnalytic(
    organizationId: organizationId,
    outletId: outletId,
    dateFrom: dateFrom,
    dateTo: dateTo,
    data: data.map((e) => e.toDomain()).toList(),
  );
}

@freezed
class ProductAnalyticDataDto with _$ProductAnalyticDataDto {
  const ProductAnalyticDataDto._();

  const factory ProductAnalyticDataDto({
    @JsonKey(name: 'product_id') required String productId,
    @JsonKey(name: 'product_name') required String productName,
    @JsonKey(name: 'category_id') required String categoryId,
    @JsonKey(name: 'category_name') required String categoryName,
    @JsonKey(name: 'quantity_sold') required int quantitySold,
    required double revenue,
    @JsonKey(name: 'average_price') required double averagePrice,
    @JsonKey(name: 'order_count') required int orderCount,
  }) = _ProductAnalyticDataDto;

  factory ProductAnalyticDataDto.fromJson(Map<String, dynamic> json) =>
      _$ProductAnalyticDataDtoFromJson(json);

  ProductAnalyticData toDomain() => ProductAnalyticData(
    productId: productId,
    productName: productName,
    categoryId: categoryId,
    categoryName: categoryName,
    quantitySold: quantitySold,
    revenue: revenue,
    averagePrice: averagePrice,
    orderCount: orderCount,
  );
}
