package cz.moneta.test.dsl.util.task.firstvision;

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.greenscreen.ARQE.ARQE02_AccountEmbossingScreen;
import cz.moneta.test.dsl.util.DateFormatPatterns;
import cz.moneta.test.dsl.util.DateUtils;
import cz.moneta.test.dsl.util.data.client.NonClient;

import java.time.LocalDate;

import static cz.moneta.test.dsl.greenscreen.AZXI.AZXI01_CustomerViewSelectScreen.CARD_NUMBER_KEY;

public class FirstVisionTasks {

    private final Harness harness;

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

    public ARQE02_AccountEmbossingScreen lookupCreditCardDetails(NonClient nonClient) {
        return harness.withGreenScreen()
                .logIn()
                .openCustomerSearch()
                    .searchByIdentificationNumber(nonClient.birthNumber())
                .openCustomerDetail()
                .openAccountDetail();
    }

    public ARQE02_AccountEmbossingScreen lookupCreditCardDetails(String birthNumber) {
        return harness.withGreenScreen()
                .logIn()
                .openCustomerSearch()
                    .searchByIdentificationNumber(birthNumber)
                .openCustomerDetail()
                .storeAccountId()
                .storeCardId()
                .openAccountDetail();
    }

    public ARQE02_AccountEmbossingScreen lookupDebitCardDetails(String accountNumber) {
        return harness.withGreenScreen()
                .logIn()
                .openCustomerViewLocateScreen()
                    .typeUniqueIdNumber("0008600060" + accountNumber)
                    .pressEnter()
                .onCustomerViewSelectScreen()
                    .storeFirstCardId()
                    .storeFirstAccountId()
                .openAccountEmbossinScreen()
                    .typeCardNumber(harness.get(CARD_NUMBER_KEY))
                    .pressEnter()
                .onAccountEmbossingScreen();
    }

    public void verifyCreditCard(NonClient nonClient, String org, String logo, String cardholderFlag, String cardAction) {
        this.lookupCreditCardDetails(nonClient)
                .checkOrg(org)
                .checkCardLogo(logo)
//                .checkName(nonClient.firstName().toUpperCase() + " " + nonClient.lastName().toUpperCase())
                .checkCardholderFlag(cardholderFlag)
                .checkCardAction(cardAction);
    }

    public void verifyDebitCard(NonClient nonClient, String accountNumber, String org, String logo, String cardAction) {
        this.lookupDebitCardDetails(accountNumber)
                .checkOrg(org)
                .checkCardLogo(logo)
                .checkName(nonClient.firstName().toUpperCase() + " " + nonClient.lastName().toUpperCase())
                .checkCardAction(cardAction);
    }

    public void verifyDebitCard (String accountNumber, String org, String logo, String cardAction) {
        this.lookupDebitCardDetails(accountNumber)
                .checkOrg(org)
                .checkCardLogo(logo)
                .checkCardAction(cardAction);
    }

    public void updateExpirationDate(String accountNumber, LocalDate expirationDate) {
        String expirationDateString = DateUtils.getDateWithFormat(expirationDate, DateFormatPatterns.FIRST_VISION_CARD_EXPIRATION_DATE);
        this.lookupDebitCardDetails(accountNumber)
                .openCardDetailsForEditing()
                .setExpirationDate(expirationDateString);
    }

    public void updateExpirationDateCC(String birthNumber, LocalDate expirationDate) {
        String expirationDateString = DateUtils.getDateWithFormat(expirationDate, DateFormatPatterns.FIRST_VISION_CARD_EXPIRATION_DATE);
        this.lookupCreditCardDetails(birthNumber)
                .openCardDetailsForEditing()
                .setExpirationDate(expirationDateString);
    }
}
