import 'package:auth/src/features/sign_up/domain/entities/sign_up_request_entity.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'address_model.dart';

part 'sign_up_request_model.freezed.dart';
part 'sign_up_request_model.g.dart';

@freezed
abstract class SignUpRequestModel with _$SignUpRequestModel {
  const factory SignUpRequestModel({
    required String firstName,
    required String lastName,
    required String email,
    required String phone,
    required String language,
    required String password,
    required List<AddressModel> taxResidences,
    required List<AddressModel> addresses,
    required int bornAt,
    required String userId,
    required String placeOfBirth,
    required String birthCountry,
    // ignore: invalid_annotation_target
    @JsonKey(name: 'document') required String documentNumber,
    required String documentType,
    // ignore: invalid_annotation_target
    @JsonKey(name: 'relationType') required String relationship,
  }) = _SignUpRequestModel;

  factory SignUpRequestModel.fromJson(Map<String, dynamic> json) =>
      _$SignUpRequestModelFromJson(json);

  @override
  @JsonKey(name: 'document')
  String get documentNumber;
  @override
  @JsonKey(name: 'relationType')
  String get relationship;
}

extension SignUpRequestModelMapper on SignUpRequestEntity {
  SignUpRequestModel toModel() => SignUpRequestModel(
    firstName: firstName,
    lastName: lastName,
    email: email,
    phone: phone,
    language: language,
    password: password,
    taxResidences: taxResidences
        .map((e) => e.toModel())
        .toList(growable: false),
    addresses: addresses.map((e) => e.toModel()).toList(growable: false),
    bornAt: bornAt,
    userId: userId,
    placeOfBirth: placeOfBirth,
    birthCountry: birthCountry,
    documentNumber: documentNumber,
    documentType: documentType,
    relationship: relationship,
  );
}
