import 'authentication.m.dart';
import 'notification.m.dart';
import 'liveConsultation.m.dart';

enum LoginStateEnum {
	Succeed,
	PasswordIncorrect,
}

class LoginResult {
	LoginStateEnum loginState;
	String? token;
	int? lockRemainingTimes;
	bool passwordExpired;
	String? accountName;

	LoginResult({
		this.loginState = LoginStateEnum.Succeed,
		this.token,
		this.lockRemainingTimes,
		this.passwordExpired = false,
		this.accountName,
	});

	factory LoginResult.fromJson(Map<String, dynamic> map) {
		return LoginResult( 
			loginState: LoginStateEnum.values.firstWhere((e) => e.index == map['LoginState']),
			token: map['Token'],
			lockRemainingTimes: map['LockRemainingTimes'],
			passwordExpired: map['PasswordExpired'],
			accountName: map['AccountName'],
		);
	}

	Map<String, dynamic> toJson() {
		final map = Map<String, dynamic>();
		map['LoginState'] = loginState.index;
		if(token != null)
			map['Token'] = token;
		if(lockRemainingTimes != null)
			map['LockRemainingTimes'] = lockRemainingTimes;
		map['PasswordExpired'] = passwordExpired;
		if(accountName != null)
			map['AccountName'] = accountName;
		return map;
	}
}

class CommonLoginRequest {
	String? anyAccount;
	String? anyCode;
	String? password;
	Map<String,String>? headerMap;
	Platform platform;
	LoginSource loginSource;

	CommonLoginRequest({
		this.anyAccount,
		this.anyCode,
		this.password,
		this.headerMap,
		this.platform = Platform.Windows,
		this.loginSource = LoginSource.PC,
	});

	factory CommonLoginRequest.fromJson(Map<String, dynamic> map) {
		return CommonLoginRequest( 
			anyAccount: map['AnyAccount'],
			anyCode: map['AnyCode'],
			password: map['Password'],
			headerMap: map['HeaderMap'] != null ? map['HeaderMap'].cast<String,String>() : null,
			platform: Platform.values.firstWhere((e) => e.index == map['Platform']),
			loginSource: LoginSource.values.firstWhere((e) => e.index == map['LoginSource']),
		);
	}

	Map<String, dynamic> toJson() {
		final map = Map<String, dynamic>();
		if(anyAccount != null)
			map['AnyAccount'] = anyAccount;
		if(anyCode != null)
			map['AnyCode'] = anyCode;
		if(password != null)
			map['Password'] = password;
		if(headerMap != null)
			map['HeaderMap'] = headerMap;
		map['Platform'] = platform.index;
		map['LoginSource'] = loginSource.index;
		return map;
	}
}

class CheckLoginTypeRequest {
	String? anyAccount;

	CheckLoginTypeRequest({
		this.anyAccount,
	});

	factory CheckLoginTypeRequest.fromJson(Map<String, dynamic> map) {
		return CheckLoginTypeRequest( 
			anyAccount: map['AnyAccount'],
		);
	}

	Map<String, dynamic> toJson() {
		final map = Map<String, dynamic>();
		if(anyAccount != null)
			map['AnyAccount'] = anyAccount;
		return map;
	}
}

class CommonSignUpRequest {
	String? anyAccount;
	String? anyCode;
	String? password;
	Map<String,String>? headerMap;

	CommonSignUpRequest({
		this.anyAccount,
		this.anyCode,
		this.password,
		this.headerMap,
	});

	factory CommonSignUpRequest.fromJson(Map<String, dynamic> map) {
		return CommonSignUpRequest( 
			anyAccount: map['AnyAccount'],
			anyCode: map['AnyCode'],
			password: map['Password'],
			headerMap: map['HeaderMap'] != null ? map['HeaderMap'].cast<String,String>() : null,
		);
	}

	Map<String, dynamic> toJson() {
		final map = Map<String, dynamic>();
		if(anyAccount != null)
			map['AnyAccount'] = anyAccount;
		if(anyCode != null)
			map['AnyCode'] = anyCode;
		if(password != null)
			map['Password'] = password;
		if(headerMap != null)
			map['HeaderMap'] = headerMap;
		return map;
	}
}

class CheckSMSVerificationCodeRequest {
	String? userPhone;
	String? verifyCode;

	CheckSMSVerificationCodeRequest({
		this.userPhone,
		this.verifyCode,
	});

	factory CheckSMSVerificationCodeRequest.fromJson(Map<String, dynamic> map) {
		return CheckSMSVerificationCodeRequest( 
			userPhone: map['UserPhone'],
			verifyCode: map['VerifyCode'],
		);
	}

	Map<String, dynamic> toJson() {
		final map = Map<String, dynamic>();
		if(userPhone != null)
			map['UserPhone'] = userPhone;
		if(verifyCode != null)
			map['VerifyCode'] = verifyCode;
		return map;
	}
}

class SendSMSVerificationCodeRequest {
	String? userPhone;

	SendSMSVerificationCodeRequest({
		this.userPhone,
	});

	factory SendSMSVerificationCodeRequest.fromJson(Map<String, dynamic> map) {
		return SendSMSVerificationCodeRequest( 
			userPhone: map['UserPhone'],
		);
	}

	Map<String, dynamic> toJson() {
		final map = Map<String, dynamic>();
		if(userPhone != null)
			map['UserPhone'] = userPhone;
		return map;
	}
}

class SendEmailVerificationCodeRequest {
	String? emailAddress;
	String? languageCode;

	SendEmailVerificationCodeRequest({
		this.emailAddress,
		this.languageCode,
	});

	factory SendEmailVerificationCodeRequest.fromJson(Map<String, dynamic> map) {
		return SendEmailVerificationCodeRequest( 
			emailAddress: map['EmailAddress'],
			languageCode: map['LanguageCode'],
		);
	}

	Map<String, dynamic> toJson() {
		final map = Map<String, dynamic>();
		if(emailAddress != null)
			map['EmailAddress'] = emailAddress;
		if(languageCode != null)
			map['LanguageCode'] = languageCode;
		return map;
	}
}

class CheckEmailVerificationCodeRequest {
	String? emailAddress;
	String? verifyCode;

	CheckEmailVerificationCodeRequest({
		this.emailAddress,
		this.verifyCode,
	});

	factory CheckEmailVerificationCodeRequest.fromJson(Map<String, dynamic> map) {
		return CheckEmailVerificationCodeRequest( 
			emailAddress: map['EmailAddress'],
			verifyCode: map['VerifyCode'],
		);
	}

	Map<String, dynamic> toJson() {
		final map = Map<String, dynamic>();
		if(emailAddress != null)
			map['EmailAddress'] = emailAddress;
		if(verifyCode != null)
			map['VerifyCode'] = verifyCode;
		return map;
	}
}

class RetrievePasswordByPhoneRequest {
	String? phone;
	String? verifyCode;
	String? newPassword;

	RetrievePasswordByPhoneRequest({
		this.phone,
		this.verifyCode,
		this.newPassword,
	});

	factory RetrievePasswordByPhoneRequest.fromJson(Map<String, dynamic> map) {
		return RetrievePasswordByPhoneRequest( 
			phone: map['Phone'],
			verifyCode: map['VerifyCode'],
			newPassword: map['NewPassword'],
		);
	}

	Map<String, dynamic> toJson() {
		final map = Map<String, dynamic>();
		if(phone != null)
			map['Phone'] = phone;
		if(verifyCode != null)
			map['VerifyCode'] = verifyCode;
		if(newPassword != null)
			map['NewPassword'] = newPassword;
		return map;
	}
}

class RetrievePasswordByEmailRequest {
	String? mail;
	String? verifyCode;
	String? newPassword;

	RetrievePasswordByEmailRequest({
		this.mail,
		this.verifyCode,
		this.newPassword,
	});

	factory RetrievePasswordByEmailRequest.fromJson(Map<String, dynamic> map) {
		return RetrievePasswordByEmailRequest( 
			mail: map['Mail'],
			verifyCode: map['VerifyCode'],
			newPassword: map['NewPassword'],
		);
	}

	Map<String, dynamic> toJson() {
		final map = Map<String, dynamic>();
		if(mail != null)
			map['Mail'] = mail;
		if(verifyCode != null)
			map['VerifyCode'] = verifyCode;
		if(newPassword != null)
			map['NewPassword'] = newPassword;
		return map;
	}
}

class VerifyAccountRequest {
	String? userName;

	VerifyAccountRequest({
		this.userName,
	});

	factory VerifyAccountRequest.fromJson(Map<String, dynamic> map) {
		return VerifyAccountRequest( 
			userName: map['UserName'],
		);
	}

	Map<String, dynamic> toJson() {
		final map = Map<String, dynamic>();
		if(userName != null)
			map['UserName'] = userName;
		return map;
	}
}

class ModifyPasswordRequest extends CommonSignUpRequest{
	String? token;
	String? newPassword;

	ModifyPasswordRequest({
		this.token,
		this.newPassword,
		String? anyAccount,
		String? anyCode,
		String? password,
		Map<String,String>? headerMap,
	}) : super(
			anyAccount: anyAccount,
			anyCode: anyCode,
			password: password,
			headerMap: headerMap,
		);

	factory ModifyPasswordRequest.fromJson(Map<String, dynamic> map) {
		return ModifyPasswordRequest( 
			token: map['Token'],
			newPassword: map['NewPassword'],
			anyAccount: map['AnyAccount'],
			anyCode: map['AnyCode'],
			password: map['Password'],
			headerMap: map['HeaderMap'] != null ? map['HeaderMap'].cast<String,String>() : null,
		);
	}

	Map<String, dynamic> toJson() {
		final map = super.toJson();
		if(token != null)
			map['Token'] = token;
		if(newPassword != null)
			map['NewPassword'] = newPassword;
		return map;
	}
}

class GenerateNewPasswordRequest extends TokenRequest{

	GenerateNewPasswordRequest({
		String? token,
	}) : super(
			token: token,
		);

	factory GenerateNewPasswordRequest.fromJson(Map<String, dynamic> map) {
		return GenerateNewPasswordRequest( 
			token: map['Token'],
		);
	}

	Map<String, dynamic> toJson() {
		final map = super.toJson();
		return map;
	}
}