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

part 'warehouse_location_dto.freezed.dart';
part 'warehouse_location_dto.g.dart';

/// WarehouseLocationDto - 백엔드 warehouses API 스키마와 100% 일치
@freezed
class WarehouseLocationDto with _$WarehouseLocationDto {
  const WarehouseLocationDto._();

  const factory WarehouseLocationDto({
    @JsonKey(name: 'Id') int? id,
    @JsonKey(name: 'Name') required String name,
    @JsonKey(name: 'zipcodes_zipcode') String? zipcodesZipcode,
    @JsonKey(name: 'zipcode_address') String? zipcodeAddress,
    @JsonKey(name: 'Remark') String? remark,
    @JsonKey(name: 'is_deleted') @Default(false) bool isDeleted,
    @JsonKey(name: 'registered_at') DateTime? registeredAt,
    @JsonKey(name: 'updated_at') DateTime? updatedAt,
    
    // Nested data (optional, populated in GET requests)
    @JsonKey(name: 'zipcode') ZipcodeDto? zipcode,
  }) = _WarehouseLocationDto;

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

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

@freezed
class WarehouseLocationRequestDto with _$WarehouseLocationRequestDto {
  const factory WarehouseLocationRequestDto({
    @JsonKey(name: 'Name') required String name,
    @JsonKey(name: 'zipcodes_zipcode') String? zipcodesZipcode,
    @JsonKey(name: 'Remark') String? remark,
  }) = _WarehouseLocationRequestDto;

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

@freezed
class WarehouseLocationUpdateRequestDto with _$WarehouseLocationUpdateRequestDto {
  const factory WarehouseLocationUpdateRequestDto({
    @JsonKey(name: 'Name') String? name,
    @JsonKey(name: 'zipcodes_zipcode') String? zipcodesZipcode,
    @JsonKey(name: 'Remark') String? remark,
  }) = _WarehouseLocationUpdateRequestDto;

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

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

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