package cz.moneta.test.dsl.util.task.ufo.operations;

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.ufo.operations.client.NewProductsUfoOps;
import cz.moneta.test.dsl.ufo.operations.client.STO702_S002_ApproveAlreadyReadPage;
import cz.moneta.test.dsl.ufo.operations.client.clientDetail.STS701_S002_AdcProductsPanel;
import cz.moneta.test.dsl.ufo.operations.client.clientDetail.STS701_S002_ClientDetailPage;

import java.util.function.Function;

public class InfoServiceTasks {
    private final Harness harness;

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

    public Function<STS701_S002_ClientDetailPage, STO702_S002_ApproveAlreadyReadPage> selectInfoServiceProductAndCheckDetails() {
        return start -> start.clickCommunicationsReminders()
                .selectNewProductForActivation(NewProductsUfoOps.ADC_INFO_SERVIS)
                .confirmAddProduct()
                .checkOmOfConsentSigning()
                .checkDateOfSigningConsent();
    }

    public Function<STS701_S002_AdcProductsPanel, STS701_S002_AdcProductsPanel> checkStartTimeAndEndTime(String startTime, String endTime) {
        return start -> start.checkStartTimeDetailOfOrder(startTime)
                .checkEndTimeDetailOfOrder(endTime);
    }

    public Function<STS701_S002_AdcProductsPanel, STS701_S002_AdcProductsPanel> fillEmailAndPhoneNumberInExpressSettings(String email, String phoneNumber) {
        return start -> start.fillEmailInputInExpressSettings(email)
                .fillTelephoneInputInExpressSettings(phoneNumber);
    }

    public Function<STS701_S002_AdcProductsPanel, STS701_S002_AdcProductsPanel> selectStartTimeAndEndTimeInExpressSettings(String startTime, String endTime) {
        return start -> start.selectStartTimeInExpressSettings(startTime)
                .selectEndTimeInExpressSettings(endTime);
    }

    public Function<STS701_S002_AdcProductsPanel, STS701_S002_AdcProductsPanel> selectStartTimeAndEndTimeInDetailOfOrder(String startTime, String endTime) {
        return start -> start.selectStartTimeInDetailOfOrder(startTime)
                .selectEndTimeInDetailOfOrder(endTime);
    }

    public Function<STS701_S002_AdcProductsPanel, STS701_S002_AdcProductsPanel> editSmsSectionInDetailOfOrder(String phoneNumber, String balance, String startTime, String endTime) {
        return start -> {
            STS701_S002_AdcProductsPanel p = start.clickSmsInDetailOfOrder()
                    .fillTelephoneInputInDetailOfOrder(phoneNumber);
            if (balance != null) {
                p.fillBalanceFrom(balance);
            }
            return p.then(selectStartTimeAndEndTimeInDetailOfOrder(startTime, endTime))
                    .clickSave();
        };
    }

    public Function<STS701_S002_AdcProductsPanel, STS701_S002_AdcProductsPanel> editEmailSectionInDetailOfOrder(String email, String balance, String startTime, String endTime) {
        return start -> {
            STS701_S002_AdcProductsPanel p = start.clickEmailInDetailOfOrder()
                    .fillEmailInputDetailOfOrder(email);
            if (balance != null) {
                p.fillBalanceFrom(balance);
            }
            return p.then(selectStartTimeAndEndTimeInDetailOfOrder(startTime, endTime))
                    .clickSave();
        };
    }
}
