package cz.moneta.test.regression.cards.localtests;

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.ufo.banka.pages.cards.credit.CardTypeAndDesign;
import cz.moneta.test.dsl.ufo.banka.tasks.BankaTasks;
import cz.moneta.test.dsl.util.credentials.Keys;
import cz.moneta.test.dsl.util.data.client.NonClient;
import cz.moneta.test.dsl.util.task.retail.cards.constants.CreditCardSQL;
import cz.moneta.test.harness.annotations.JiraTestCase;
import cz.moneta.test.harness.annotations.TestCase;
import cz.moneta.test.harness.annotations.TestScenario;
import cz.moneta.test.harness.endpoints.ods.OdsEndpoint;
import cz.moneta.test.harness.support.auth.Credentials;
import cz.moneta.test.harness.support.auth.Key;
import org.jooq.Record;
import org.jooq.Result;
import org.junit.jupiter.api.BeforeAll;

import static cz.moneta.test.harness.annotations.Environment.PPE;
import static cz.moneta.test.harness.annotations.Environment.TST1;

@TestScenario(name = "Teller must be able to crate a new gold debit card for existing client")
public class CreateGoldDebitCardForExistingCustomer {

    NonClient nonClient;

    @BeforeAll
    public void setup(Harness harness) {
        nonClient = harness.data().newFVNonClient()
                .withBirthNumber(harness.getConfig("cards_team.retail.rc"));
    }

    @TestCase(name = "Gold virtual debit card for existing client", environments = {TST1, PPE})
    @JiraTestCase(id = "CT-T9374")
    public void goldVirtualDCForExistingClient(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        long accountNumber=Long.parseLong(harness.getConfig("cards_team.retail.account.number3"));

        BankaTasks bankaTasks = harness.tasks().ufo().banka();
        harness.withUfo()
                .openLoginPage()
                .then(bankaTasks.login().withCredentialsAndTurnOffSignpad(credentials))
                .then(bankaTasks.search().findByRC(nonClient.birthNumber()))
                .then(bankaTasks.cardsOnboarding().createNewGoldDebitCardForExistingCurrentAccount(CardTypeAndDesign.GOLD.getValue(), accountNumber));

        Result<Record> resultList = harness.getEndpoint(OdsEndpoint.class).executeSql(CreditCardSQL.FIND_ONBOARDED_CARDS_BY_RC.replaceAll("ID_NUMBER", nonClient.birthNumber()));
        harness.store("reports.tmfj.execution.comment", "Rč klienta: " + nonClient.birthNumber() + "\n Číslo karty: " + resultList.getValue(0, 1));
    }
}