package cz.moneta.test.dsl.ufo.operations.ufoOperations;

import cz.moneta.test.dsl.util.data.client.NonClient;
import cz.moneta.test.dsl.util.data.client.OccupationStatus;
import cz.moneta.test.harness.context.StoreAccessor;
import cz.moneta.test.harness.endpoints.ufo.UfoEndpoint;
import cz.moneta.test.harness.support.web.*;

import static cz.moneta.test.dsl.ufo.operations.shared.SharedElements.LOAD_IMG_DIV_CLASS;
import static cz.moneta.test.dsl.ufo.operations.ufoOperations.ACQ702_S005_ConfirmationOfIncome.SEND;
import static cz.moneta.test.dsl.util.DateFormatPatterns.CZ_DATE_FORMAT;
import static cz.moneta.test.dsl.util.DateUtils.getDateWithFormat;

@Wait(value = LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE, waitSecondsForElement = 50)
@Wait(value = SEND, waitSecondsForElement = 50)
public interface ACQ702_S005_ConfirmationOfIncome extends WebFlow<ACQ702_S005_ConfirmationOfIncome>, StoreAccessor {

    String LAST_NAME = "//input[@id='ACQ702_S005_E002' and @type='text']";
    String SURNAME = "ACQ702_S005_E004";
    String EMPLOYED_SINCE = "ACQ702_S005_E016";
    String EMPLOYED_TILL = "ACQ702_S005_E014";
    String EMPLOYMENT_TYPE = "ACQ702_S005_C005";
    String NET_EARNINGS = "ACQ702_S005_E015";
    String INSTALMENT = "ACQ702_S005_E017";
    String WAGE_DEDUCTIONS = "ACQ702_S005_E010";
    String DEPENDING_PEOPLE = "ACQ702_S005_E018";
    String EMPLOYER_NAME = "ACQ702_S005_E005";
    String EMPLOYER_STREET = "ACQ702_S005_E006";
    String EMPLOYER_DESCRIPTION_NUMBER = "ACQ702_S005_E007";
    String EMPLOYER_ORIENTATION_NUMBER = "ACQ702_S005_E019";
    String EMPLOYER_CITY = "ACQ702_S005_E008";
    String EMPLOYER_POST_CODE = "ACQ702_S005_E009";
    String EMPLOYER_ICO = "ACQ702_S005_E011";
    String ISSUE_DATE = "ACQ702_S005_E012";
    String STAMP = "ACQ702_S005_H002_1";
    String SIGNATURE = "ACQ702_S005_H001_1";

    String SEND = "ACQ702_S005_B001";
    String SEND_AGREE = "SCH708_S001_B001";
    String FINAL_AGREE = "SCH711_S002_B002";

    @Wait(value = LAST_NAME, by = Lookup.XPATH)
    @TypeInto(value = LAST_NAME, by = Lookup.XPATH)
    ACQ702_S005_ConfirmationOfIncome fillLastName(String lastName);

    @TypeInto(value = SURNAME)
    ACQ702_S005_ConfirmationOfIncome fillSurname(String firstName);

    @TypeInto(value = EMPLOYED_SINCE)
    ACQ702_S005_ConfirmationOfIncome fillEmployedSince(String employedSince);

    /**
     * @param type (doba určitá,doba neurčitá)
     */
    @Select(value = EMPLOYMENT_TYPE)
    ACQ702_S005_ConfirmationOfIncome selectEmployemntType(String type);

    @TypeInto(value = NET_EARNINGS)
    ACQ702_S005_ConfirmationOfIncome fillNetEarnings(String netEarnings);

    @TypeInto(value = INSTALMENT)
    ACQ702_S005_ConfirmationOfIncome fillInstalment(String instalment);

    @TypeInto(value = WAGE_DEDUCTIONS)
    ACQ702_S005_ConfirmationOfIncome fillWageDeductions(String wageDeductions);

    @TypeInto(value = DEPENDING_PEOPLE)
    ACQ702_S005_ConfirmationOfIncome fillDependingPeople(String dependingPeople);

    @TypeInto(value = EMPLOYER_NAME)
    ACQ702_S005_ConfirmationOfIncome fillEmployerName(String employerName);

    @TypeInto(value = EMPLOYER_STREET)
    ACQ702_S005_ConfirmationOfIncome fillEmployerStreet(String employerStreet);

    @TypeInto(value = EMPLOYER_DESCRIPTION_NUMBER)
    ACQ702_S005_ConfirmationOfIncome fillDescriptionNumber(String descriptionNumber);

    @TypeInto(value = EMPLOYER_ORIENTATION_NUMBER)
    ACQ702_S005_ConfirmationOfIncome fillOrientationNumber(String orientationNumber);

    @TypeInto(value = EMPLOYER_CITY)
    ACQ702_S005_ConfirmationOfIncome fillEmployerCity(String employerCity);

    @TypeInto(value = EMPLOYER_POST_CODE)
    ACQ702_S005_ConfirmationOfIncome fillEmployerPostCode(String postCode);

    @TypeInto(value = EMPLOYER_ICO)
    ACQ702_S005_ConfirmationOfIncome fillEmployerIco(String ico);

    @TypeInto(value = ISSUE_DATE)
    ACQ702_S005_ConfirmationOfIncome fillIssueDate(String issueDate);

    @Click(value = STAMP)
    ACQ702_S005_ConfirmationOfIncome clickStamp();

    @Click(value = SIGNATURE)
    ACQ702_S005_ConfirmationOfIncome clickSignature();

    @Click(value = SEND, andWait = @Wait(value = LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE, waitSecondsForElement = 30))
    ACQ702_S005_ConfirmationOfIncome clickSend();

    @Wait(value = SEND_AGREE)
    @Click(value = SEND_AGREE, andWait = @Wait(value = LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE, waitSecondsForElement = 30))
    ACQ702_S005_ConfirmationOfIncome clickSendAgree();

    @Wait(value = FINAL_AGREE)
    @Click(value = FINAL_AGREE, andWait = @Wait(value = LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE, waitSecondsForElement = 30))
    ACQ702_S005_ConfirmationOfIncome clickFinalAgree();

    @CustomAction
    default ACQ702_S005_ConfirmationOfIncome fillEmploymentTillIfPresent(NonClient client) {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        if (client.occupationStatus() == OccupationStatus.FULL_TIME_EMPLOYEE_FINITE) {
            endpoint.type(() -> EMPLOYED_TILL, getDateWithFormat(client.occupationEmploymentTillRaw(), CZ_DATE_FORMAT), true);
        }
        return null;
    }

    @CustomAction
    default UKO720_S001_TaskDetail closeWindow() {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        endpoint.closePopup(20);
        return null;
    }
}