import 'package:freezed_annotation/freezed_annotation.dart';

part 'company_dto.freezed.dart';
part 'company_dto.g.dart';

@freezed
class CreateCompanyRequest with _$CreateCompanyRequest {
  const factory CreateCompanyRequest({
    required String name,
    required String address,
    @JsonKey(name: 'contact_name') required String contactName,
    @JsonKey(name: 'contact_position') required String contactPosition,
    @JsonKey(name: 'contact_phone') required String contactPhone,
    @JsonKey(name: 'contact_email') required String contactEmail,
    @JsonKey(name: 'company_types') @Default([]) List<String> companyTypes,
    String? remark,
  }) = _CreateCompanyRequest;

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

@freezed
class UpdateCompanyRequest with _$UpdateCompanyRequest {
  const factory UpdateCompanyRequest({
    String? name,
    String? address,
    @JsonKey(name: 'contact_name') String? contactName,
    @JsonKey(name: 'contact_position') String? contactPosition,
    @JsonKey(name: 'contact_phone') String? contactPhone,
    @JsonKey(name: 'contact_email') String? contactEmail,
    @JsonKey(name: 'company_types') List<String>? companyTypes,
    String? remark,
    @JsonKey(name: 'is_active') bool? isActive,
  }) = _UpdateCompanyRequest;

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

@freezed
class CompanyResponse with _$CompanyResponse {
  const factory CompanyResponse({
    required int id,
    required String name,
    required String address,
    @JsonKey(name: 'contact_name') required String contactName,
    @JsonKey(name: 'contact_position') String? contactPosition,  // nullable로 변경
    @JsonKey(name: 'contact_phone') required String contactPhone,
    @JsonKey(name: 'contact_email') required String contactEmail,
    @JsonKey(name: 'company_types') @Default([]) List<String> companyTypes,
    String? remark,
    @JsonKey(name: 'is_active') required bool isActive,
    @JsonKey(name: 'created_at') required DateTime createdAt,
    @JsonKey(name: 'updated_at') DateTime? updatedAt,  // nullable로 변경
    @JsonKey(name: 'address_id') int? addressId,
  }) = _CompanyResponse;

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

@freezed
class CompanyNameDto with _$CompanyNameDto {
  const factory CompanyNameDto({
    required int id,
    required String name,
  }) = _CompanyNameDto;

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