import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:superport/data/models/equipment_history_dto.dart'; part 'maintenance_dto.freezed.dart'; part 'maintenance_dto.g.dart'; @freezed class MaintenanceDto with _$MaintenanceDto { const MaintenanceDto._(); // Private constructor for getters const factory MaintenanceDto({ @JsonKey(name: 'id') int? id, @JsonKey(name: 'equipment_history_id') int? equipmentHistoryId, // Optional in backend @JsonKey(name: 'started_at') required DateTime startedAt, @JsonKey(name: 'ended_at') required DateTime endedAt, @JsonKey(name: 'period_month') @Default(1) int periodMonth, @JsonKey(name: 'maintenance_type') @Default('WARRANTY') String maintenanceType, // WARRANTY|CONTRACT|INSPECTION @JsonKey(name: 'is_deleted') @Default(false) bool isDeleted, @JsonKey(name: 'registered_at') required DateTime registeredAt, @JsonKey(name: 'updated_at') DateTime? updatedAt, // 백엔드 추가 필드들 (계산된 값) @JsonKey(name: 'equipment_serial') String? equipmentSerial, @JsonKey(name: 'equipment_model') String? equipmentModel, @JsonKey(name: 'days_remaining') int? daysRemaining, @JsonKey(name: 'is_expired') @Default(false) bool isExpired, // Related entities (optional, populated in GET requests) EquipmentHistoryDto? equipmentHistory, }) = _MaintenanceDto; // isActive 계산 속성 (is_deleted의 반대) bool get isActive => !isDeleted; factory MaintenanceDto.fromJson(Map json) => _$MaintenanceDtoFromJson(json); } @freezed class MaintenanceRequestDto with _$MaintenanceRequestDto { const factory MaintenanceRequestDto({ @JsonKey(name: 'equipment_history_id') int? equipmentHistoryId, // Optional in backend @JsonKey(name: 'started_at') required DateTime startedAt, @JsonKey(name: 'ended_at') required DateTime endedAt, @JsonKey(name: 'period_month') @Default(1) int periodMonth, @JsonKey(name: 'maintenance_type') @Default('WARRANTY') String maintenanceType, // WARRANTY|CONTRACT|INSPECTION }) = _MaintenanceRequestDto; factory MaintenanceRequestDto.fromJson(Map json) => _$MaintenanceRequestDtoFromJson(json); } @freezed class MaintenanceUpdateRequestDto with _$MaintenanceUpdateRequestDto { const factory MaintenanceUpdateRequestDto({ @JsonKey(name: 'started_at') DateTime? startedAt, @JsonKey(name: 'ended_at') DateTime? endedAt, @JsonKey(name: 'period_month') int? periodMonth, @JsonKey(name: 'maintenance_type') String? maintenanceType, }) = _MaintenanceUpdateRequestDto; factory MaintenanceUpdateRequestDto.fromJson(Map json) => _$MaintenanceUpdateRequestDtoFromJson(json); } @freezed class MaintenanceListResponse with _$MaintenanceListResponse { const factory MaintenanceListResponse({ @JsonKey(name: 'data') required List 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, }) = _MaintenanceListResponse; factory MaintenanceListResponse.fromJson(Map json) => _$MaintenanceListResponseFromJson(json); } @freezed class MaintenanceQueryDto with _$MaintenanceQueryDto { const factory MaintenanceQueryDto({ @JsonKey(name: 'equipment_id') int? equipmentId, @JsonKey(name: 'maintenance_type') String? maintenanceType, @JsonKey(name: 'is_expired') bool? isExpired, @JsonKey(name: 'expiring_days') int? expiringDays, @JsonKey(name: 'page') @Default(1) int page, @JsonKey(name: 'per_page') @Default(10) int perPage, @JsonKey(name: 'include_deleted') @Default(false) bool includeDeleted, }) = _MaintenanceQueryDto; factory MaintenanceQueryDto.fromJson(Map json) => _$MaintenanceQueryDtoFromJson(json); } // Maintenance Type 헬퍼 (백엔드와 일치) class MaintenanceType { static const String warranty = 'WARRANTY'; static const String contract = 'CONTRACT'; static const String inspection = 'INSPECTION'; static String getDisplayName(String type) { switch (type) { case warranty: return '무상 보증'; case contract: return '유상 계약'; case inspection: return '점검'; default: return type; } } static List get allTypes => [warranty, contract, inspection]; static List> get typeOptions => [ {'value': warranty, 'label': '무상 보증'}, {'value': contract, 'label': '유상 계약'}, {'value': inspection, 'label': '점검'}, ]; }