import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:superport/data/models/equipment_history_dto.dart';

part 'rent_dto.freezed.dart';
part 'rent_dto.g.dart';

@freezed
class RentDto with _$RentDto {
  const RentDto._(); // Private constructor for getters

  const factory RentDto({
    int? id,
    @JsonKey(name: 'started_at') required DateTime startedAt,
    @JsonKey(name: 'ended_at') required DateTime endedAt,
    @JsonKey(name: 'equipment_history_Id') required int equipmentHistoryId,
    
    // Related entities (optional, populated in GET requests)
    EquipmentHistoryDto? equipmentHistory,
  }) = _RentDto;

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

@freezed
class RentRequestDto with _$RentRequestDto {
  const factory RentRequestDto({
    @JsonKey(name: 'started_at') required DateTime startedAt,
    @JsonKey(name: 'ended_at') required DateTime endedAt,
    @JsonKey(name: 'equipment_history_Id') required int equipmentHistoryId,
  }) = _RentRequestDto;

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

@freezed
class RentUpdateRequestDto with _$RentUpdateRequestDto {
  const factory RentUpdateRequestDto({
    @JsonKey(name: 'started_at') DateTime? startedAt,
    @JsonKey(name: 'ended_at') DateTime? endedAt,
    @JsonKey(name: 'equipment_history_Id') int? equipmentHistoryId,
  }) = _RentUpdateRequestDto;

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

@freezed
class RentListResponse with _$RentListResponse {
  const factory RentListResponse({
    @JsonKey(name: 'data') required List<RentDto> items,
    @JsonKey(name: 'total') required int totalCount,
    @JsonKey(name: 'page') required int currentPage,
    @JsonKey(name: 'total_pages') required int totalPages,
    @JsonKey(name: 'page_size') int? pageSize,
  }) = _RentListResponse;

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