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

part 'equipment_history_companies_link_dto.freezed.dart';
part 'equipment_history_companies_link_dto.g.dart';

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

  const factory EquipmentHistoryCompaniesLinkDto({
    @JsonKey(name: 'Id') int? id,
    @JsonKey(name: 'companies_id') required int companiesId,
    @JsonKey(name: 'equipment_history_Id') required int equipmentHistoryId,
    @JsonKey(name: 'Order') @Default(1) int order,
    @JsonKey(name: 'is_deleted') @Default(false) bool isDeleted,
    @JsonKey(name: 'registered_at') required DateTime registeredAt,
    @JsonKey(name: 'updated_at') DateTime? updatedAt,
    
    // Related entities (optional, populated in GET requests)
    CompanyDto? company,
    EquipmentHistoryDto? equipmentHistory,
  }) = _EquipmentHistoryCompaniesLinkDto;

  // isActive 계산 속성 (is_deleted의 반대)
  bool get isActive => !isDeleted;

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

@freezed
class EquipmentHistoryCompaniesLinkRequestDto with _$EquipmentHistoryCompaniesLinkRequestDto {
  const factory EquipmentHistoryCompaniesLinkRequestDto({
    @JsonKey(name: 'companies_id') required int companiesId,
    @JsonKey(name: 'equipment_history_Id') required int equipmentHistoryId,
    @JsonKey(name: 'Order') @Default(1) int order,
  }) = _EquipmentHistoryCompaniesLinkRequestDto;

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

@freezed
class EquipmentHistoryCompaniesLinkUpdateRequestDto with _$EquipmentHistoryCompaniesLinkUpdateRequestDto {
  const factory EquipmentHistoryCompaniesLinkUpdateRequestDto({
    @JsonKey(name: 'companies_id') int? companiesId,
    @JsonKey(name: 'equipment_history_Id') int? equipmentHistoryId,
    @JsonKey(name: 'Order') int? order,
  }) = _EquipmentHistoryCompaniesLinkUpdateRequestDto;

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

@freezed
class EquipmentHistoryCompaniesLinkListResponse with _$EquipmentHistoryCompaniesLinkListResponse {
  const factory EquipmentHistoryCompaniesLinkListResponse({
    @JsonKey(name: 'data') required List<EquipmentHistoryCompaniesLinkDto> 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,
  }) = _EquipmentHistoryCompaniesLinkListResponse;

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