package cz.moneta.test.dsl.util.task.cagw.api;

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.cagw.api.v1.external.product.cloan.application.Address;
import cz.moneta.test.dsl.cagw.api.v1.external.product.cloan.application.Client;
import cz.moneta.test.dsl.util.DateUtils;
import cz.moneta.test.dsl.util.data.client.NonClient;

public class ClientTasks {

    private final Harness harness;

    public ClientTasks(Harness harness) {
        this.harness = harness;
    }

    public Client from(NonClient nonClient) {
        return Client.builder()
                .firstname(nonClient.firstName())
                .lastname(nonClient.lastName())
                .birthNumber(nonClient.birthNumber())
                .primaryProofOfIdentity(Client.ProofOfIdentity.builder()
                        .type("IDENTITY_CARD")
                        .number(nonClient.idCardNumber())
                        .expirationDate(nonClient.idCardExpiredRaw())
                        .issuingCountry("CZ")
                        .build())
                .secondaryProofOfIdentity(Client.ProofOfIdentity.builder()
                        .type("PASSPORT")
                        .number(nonClient.passportId())
                        .expirationDate(nonClient.passportExpiryDateRaw())
                        .issuingCountry("CZ")
                        .build())
                .nationality("CZ")
                .contactAddress(Address.builder()
                        .street(nonClient.residencyAddress().getStreet())
                        .descriptiveNumber(nonClient.residencyAddress().getDescriptiveNumber())
                        .town(nonClient.residencyAddress().getCity())
                        .zip(nonClient.residencyAddress().getZip())
                        .country(nonClient.residencyAddress().getCountry())
                        .build())
                .permanentAddress(Address.builder()
                        .street(nonClient.residencyAddress().getStreet())
                        .descriptiveNumber(nonClient.residencyAddress().getDescriptiveNumber())
                        .town(nonClient.residencyAddress().getCity())
                        .zip(nonClient.residencyAddress().getZip())
                        .country(nonClient.residencyAddress().getCountry())
                        .build())
                .currentAddressSinceYear(nonClient.currentAddressSinceYear())
                .phoneNumber("420" + nonClient.mobileNumber())
                .email(nonClient.email())
                .maritalStatus(nonClient.maritalStatus().getApiValue())
                .accommodationType(nonClient.accommodationType().getApiValue())
                .educationLevel(nonClient.educationLevel().getApiValue())
                .occupation(Client.Occupation.builder()
                        .status(nonClient.occupationStatus().getApiValue())
                        .code(Integer.parseInt(nonClient.occupationType().getHCisValue()))
                        .institution(Client.Institution.builder()
                                .name(nonClient.employer().getName())
                                .ico(nonClient.employer().getIco())
                                .phoneNumber("420" + nonClient.employer().getPhoneNumber())
                                .address(Address.builder()
                                        .street(nonClient.employer().getAddress().getStreet())
                                        .descriptiveNumber(nonClient.employer().getAddress().getDescriptiveNumber())
                                        .orientationNumber(nonClient.employer().getAddress().getOrientationNumber())
                                        .town(nonClient.employer().getAddress().getCity())
                                        .zip(nonClient.employer().getAddress().getZip())
                                        .country(nonClient.employer().getAddress().getCountry())
                                        .build())
                                .build())
                        .employmentFrom(DateUtils.getDateWithFormat(nonClient.occupationEmploymentFromRaw(), "yyyy-MM-dd"))
                        .onNotice(nonClient.occupationOnNotice())
                        .trialPeriod(nonClient.occupationTrialPeriod())
                        .build())
                .consents(Client.Consents.builder()
                        .dataProcessing(nonClient.consentsDataProcessing())
                        .debtRegisterCheck(nonClient.consentsDebtRegisterCheck())
                        .build())
                .netMonthlyIncome(nonClient.netMonthlyIncome())
                .homeIncome(nonClient.homeIncome())
                .dependentPersons(nonClient.dependants())
                .otherLoanPayments(nonClient.otherLoanPayments())
                .wageDeductions(nonClient.wageDeductions())
                .otherExpenses(nonClient.otherExpenses())
                .build();
    }
}
