import 'package:json_annotation/json_annotation.dart';

part 'login_data.g.dart';


@JsonSerializable(explicitToJson: true, constructor: 'build')
class LoginData {
  final String login;
  final String password;
  final String locale;

  const LoginData._({
    required this.login,
    required this.password,
    required this.locale,
  });

  factory LoginData.build({
    required String login,
    required String password,
    required String locale,
  }) => LoginData._(
    login: login.trim().toLowerCase(),
    password: password,
    locale: locale,
  );

  factory LoginData.fromJson(Map<String, dynamic> json) => _$LoginDataFromJson(json);
  Map<String, dynamic> toJson() => _$LoginDataToJson(this);
}

@JsonSerializable(explicitToJson: true, constructor: 'buildIstance')
class AccountData extends LoginData {
  final String name;
  final String lastName;

  const AccountData._({
    required super.login,
    required super.password,
    required super.locale,
    required this.name,
    required this.lastName,
  }) : super._();

  factory AccountData.buildIstance({
    required String login,
    required String password,
    required String locale,
    required String name,
    required String lastName,
  }) => AccountData._(
    login: login,
    password: password,
    locale: locale,
    name: name.trim(),
    lastName: lastName.trim(),
  );

  factory AccountData.build({
    required LoginData login,
    required String name,
    required String lastName,
  }) => AccountData.buildIstance(
    login: login.login,
    password: login.password,
    locale: login.locale,
    name: name,
    lastName: lastName,
  );


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

  @override
  Map<String, dynamic> toJson() => _$AccountDataToJson(this);
}
