part of '../auth_dtos.dart';

@freezed
class LoginDto with _$LoginDto {
  const factory LoginDto({
    @JsonKey(name: 'status') String? status,
    @JsonKey(name: 'message') String? message,
    @JsonKey(name: 'data') LoginDataDto? data,
  }) = _LoginDto;

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

  const LoginDto._();

  /// mapping ke domain
  Login toDomain() => Login(
    status: status ?? '',
    message: message ?? '',
    accessToken: data?.accessToken ?? '',
    refreshToken: data?.refreshToken ?? '',
    user: data?.user?.toDomain() ?? User.empty(),
  );
}

@freezed
class LoginDataDto with _$LoginDataDto {
  const factory LoginDataDto({
    @JsonKey(name: 'access_token') String? accessToken,
    @JsonKey(name: 'refresh_token') String? refreshToken,
    @JsonKey(name: 'user') UserDto? user,
  }) = _LoginDataDto;

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

@freezed
class UserDto with _$UserDto {
  const factory UserDto({
    @JsonKey(name: 'id') String? id,
    @JsonKey(name: 'name') String? name,
    @JsonKey(name: 'phone_number') String? phoneNumber,
    @JsonKey(name: 'birth_date') String? birthDate,
  }) = _UserDto;

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

  const UserDto._();

  User toDomain() => User(
    id: id ?? '',
    name: name ?? '',
    phoneNumber: phoneNumber ?? '',
    birthDate: birthDate ?? '',
  );
}
