import 'package:freezed_annotation/freezed_annotation.dart';

part 'lookup_data.freezed.dart';
part 'lookup_data.g.dart';

/// 전체 Lookups 데이터 컨테이너 (백엔드 API 응답 형식)
@freezed
class LookupData with _$LookupData {
  const factory LookupData({
    @JsonKey(name: 'manufacturers', defaultValue: []) required List<LookupItem> manufacturers,
    @JsonKey(name: 'equipment_names', defaultValue: []) required List<EquipmentNameItem> equipmentNames,
    @JsonKey(name: 'equipment_categories', defaultValue: []) required List<CategoryCombinationItem> equipmentCategories,
    @JsonKey(name: 'equipment_statuses', defaultValue: []) required List<StatusItem> equipmentStatuses,
    @JsonKey(name: 'companies', defaultValue: []) required List<LookupItem> companies,
    @JsonKey(name: 'warehouses', defaultValue: []) required List<LookupItem> warehouses,
  }) = _LookupData;

  /// 빈 lookups 데이터 생성 (백엔드 API 없을 때 사용)
  factory LookupData.empty() => const LookupData(
    manufacturers: [],
    equipmentNames: [],
    equipmentCategories: [],
    equipmentStatuses: [],
    companies: [],
    warehouses: [],
  );

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

/// 기본 Lookup 아이템 (제조사용)
@freezed
class LookupItem with _$LookupItem {
  const factory LookupItem({
    int? id,
    required String name,
  }) = _LookupItem;

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

/// 장비명 Lookup 아이템 (제조사 정보 포함)
@freezed
class EquipmentNameItem with _$EquipmentNameItem {
  const factory EquipmentNameItem({
    int? id,
    required String name,
    @JsonKey(name: 'model_number') String? modelNumber,
  }) = _EquipmentNameItem;

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

/// 카테고리 조합 Lookup 아이템 (백엔드 API 실제 구조)
@freezed
class CategoryCombinationItem with _$CategoryCombinationItem {
  const factory CategoryCombinationItem({
    required String category1,
    required String category2,
    required String category3,
  }) = _CategoryCombinationItem;

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

/// 개별 카테고리 아이템 (UI용)
@freezed
class CategoryItem with _$CategoryItem {
  const factory CategoryItem({
    required String id,
    required String name,
    String? description,
  }) = _CategoryItem;

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

/// 상태 Lookup 아이템
@freezed
class StatusItem with _$StatusItem {
  const factory StatusItem({
    required String id,
    required String name,
    String? description,
  }) = _StatusItem;

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