part of '../analytic_dtos.dart';

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

  const factory ProductAnalyticDto({
    @JsonKey(name: 'organization_id') String? organizationId,
    @JsonKey(name: 'outlet_id') String? outletId,
    @JsonKey(name: 'date_from') String? dateFrom,
    @JsonKey(name: 'date_to') String? dateTo,
    @JsonKey(name: 'data') 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') String? productId,
    @JsonKey(name: 'product_name') String? productName,
    @JsonKey(name: 'category_id') String? categoryId,
    @JsonKey(name: 'category_name') String? categoryName,
    @JsonKey(name: 'quantity_sold') int? quantitySold,
    @JsonKey(name: 'revenue') int? revenue,
    @JsonKey(name: 'average_price') double? averagePrice,
    @JsonKey(name: 'order_count') 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 ?? 0,
    revenue: revenue ?? 0,
    averagePrice: averagePrice ?? 0,
    orderCount: orderCount ?? 0,
  );
}
