import 'package:functions/src/features/activity_meter/domain/entities/activity_entity.dart';
import 'package:freezed_annotation/freezed_annotation.dart';

part 'get_device_steps_response_model.freezed.dart';
part 'get_device_steps_response_model.g.dart';

@freezed
abstract class GetDeviceStepsResponseModel with _$GetDeviceStepsResponseModel {
  const factory GetDeviceStepsResponseModel({
    required List<GetDeviceStepsItemResponseModel> items,
  }) = _GetDeviceStepsResponseModel;

  factory GetDeviceStepsResponseModel.fromJson(Map<String, dynamic> json) =>
      _$GetDeviceStepsResponseModelFromJson(json);
}

@freezed
abstract class GetDeviceStepsItemResponseModel with _$GetDeviceStepsItemResponseModel {
  const factory GetDeviceStepsItemResponseModel({
    required String id,
    required String deviceIdentificator,
    required int steps,
    required int totalSteps,
    required int occurredAt,
    required int createdAt,
  }) =
  _GetDeviceStepsItemResponseModel;

  factory GetDeviceStepsItemResponseModel.fromJson(Map<String, dynamic> json) =>
      _$GetDeviceStepsItemResponseModelFromJson(json);
}

extension GetDeviceStepsResponseModelMapper on GetDeviceStepsResponseModel {
  List<ActivityEntity> toEntity() {
    return items.map((GetDeviceStepsItemResponseModel item) => ActivityEntity(
      id: item.id,
      deviceIdentificator: item.deviceIdentificator,
      steps: item.steps,
      totalSteps: item.totalSteps,
      occurredAt: DateTime.fromMillisecondsSinceEpoch(item.occurredAt),
      createdAt: item.createdAt,
    )).toList();
  }
}