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

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.ib.authentication.LoginPage;
import cz.moneta.test.dsl.ib.insurance.InsurancePage;
import cz.moneta.test.dsl.ib.insurance.accident.AccidentInsuranceCreatePage;
import cz.moneta.test.dsl.ib.insurance.travel.LongTermTravelInsuranceCreatePage;
import cz.moneta.test.dsl.ib.insurance.travel.ShortTermTravelInsuranceCreatePage;
import cz.moneta.test.harness.support.auth.Credentials;

import java.util.function.Function;

public class InsuranceIbTasks {

    private final Harness harness;
    final String SMS_CODE = "12341234";

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

    public Function<LoginPage, InsurancePage> loginWithDefaultMobileKeyAndClickInsurance(Credentials credentials) {
        return start -> start.typeUsername(credentials.getUsername())
                .typePassword(credentials.getPassword())
                .clickLogin()
                .onAuthMobileKeyPage()
                .fillMobileKey(SMS_CODE)
                .clickLogin()
                .onWelcomePage()
                .checkAndConfirmCookies()
                .clickInsurance();
    }

    public Function<AccidentInsuranceCreatePage, InsurancePage> createAccidentInsuranceWithDefaultMobileKey() {
        return start -> start.clickLicenceAgreement()
                .clickInsuranceAgreement()
                .clickContinueButton()
                .typeSmsCode(SMS_CODE)
                .clickSend()
                .clickListInsurace();
    }

    public Function<LongTermTravelInsuranceCreatePage, InsurancePage> createLongTermTravelInsuranceWithDefaultMobileKey() {
        return start -> start.clickLicenceAgreement()
                .clickInsuranceAgreement()
                .clickContinueButton()
                .typeSmsCode(SMS_CODE)
                .clickSend()
                .clickListInsurace();
    }

    public Function<ShortTermTravelInsuranceCreatePage, InsurancePage> createShortTermTravelInsuranceWithDefaultMobileKey() {
        return start -> start.clickLicenceAgreement()
                .clickInsuranceAgreement()
                .clickContinueButton()
                .typeSmsCode(SMS_CODE)
                .clickSend()
                .clickListInsurace();
    }
}