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: 'outlet_name') String? outletName,
    @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 ?? "",
    outletName: outletName ?? "",
    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: 'product_sku') String? productSku,
    @JsonKey(name: 'product_price') int? productPrice,
    @JsonKey(name: 'category_id') String? categoryId,
    @JsonKey(name: 'category_name') String? categoryName,
    @JsonKey(name: 'category_order') int? categoryOrder,
    @JsonKey(name: 'quantity_sold') int? quantitySold,
    @JsonKey(name: 'revenue') int? revenue,
    @JsonKey(name: 'average_price') double? averagePrice,
    @JsonKey(name: 'order_count') int? orderCount,
    @JsonKey(name: 'standard_hpp_per_unit') int? standardHppPerUnit,
    @JsonKey(name: 'standard_hpp_total') int? standardHppTotal,
    @JsonKey(name: 'fifo_hpp_per_unit') int? fifoHppPerUnit,
    @JsonKey(name: 'fifo_hpp_total') int? fifoHppTotal,
    @JsonKey(name: 'moving_average_hpp_per_unit') int? movingAverageHppPerUnit,
    @JsonKey(name: 'moving_average_hpp_total') int? movingAverageHppTotal,
  }) = _ProductAnalyticDataDto;

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

  ProductAnalyticData toDomain() => ProductAnalyticData(
    productId: productId ?? "",
    productName: productName ?? "",
    productSku: productSku ?? "",
    productPrice: productPrice ?? 0,
    categoryId: categoryId ?? "",
    categoryName: categoryName ?? "",
    categoryOrder: categoryOrder ?? 0,
    quantitySold: quantitySold ?? 0,
    revenue: revenue ?? 0,
    averagePrice: averagePrice ?? 0,
    orderCount: orderCount ?? 0,
    standardHppPerUnit: standardHppPerUnit ?? 0,
    standardHppTotal: standardHppTotal ?? 0,
    fifoHppPerUnit: fifoHppPerUnit ?? 0,
    fifoHppTotal: fifoHppTotal ?? 0,
    movingAverageHppPerUnit: movingAverageHppPerUnit ?? 0,
    movingAverageHppTotal: movingAverageHppTotal ?? 0,
  );
}
