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

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.harness.context.StoreAccessor;
import cz.moneta.test.harness.endpoints.ufo.UfoEndpoint;
import cz.moneta.test.harness.support.web.*;
import org.junit.jupiter.api.Assertions;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

import static cz.moneta.test.dsl.ufo.operations.shared.SharedElements.LOAD_IMG_DIV_CLASS;
import static cz.moneta.test.dsl.ufo.operations.ufoOperations.UKO720_S001_TaskPage.TASK_ID_KEY;

public interface STI701_S002_PostPanel extends StoreAccessor, WebFlow<STI701_S002_PostPanel> {

    String STATEMENT_TO_REQUIREMENT_COMPOSING_ANSWER = "ufo-et-STI701_S002_F003_row_8_sel";
    String SALUTATION_COMBOBOX_RIGHT = "STI701_S002_C006";
    String SALUTATION_COMBOBOX_LEFT = "STI701_S002_C005";
    String CLIENT_NAME_INPUT = "STI701_S002_E014";
    String STREET_DESC_NO_INPUT = "STI701_S002_E015";
    String CITY_INPUT = "STI701_S002_E017";
    String POSTAL_CODE_INPUT = "STI701_S002_E016";
    String INFLECT_CLIENT_NAME_INPUT = "STI701_S002_E009";
    String TASK_ID_INPUT = "STI701_S002_E010";
    String DATE_OF_ACCEPTANCE_REQUIREMENT_INPUT = "STI701_S002_E011";
    String MM_BANK_RADIO = "STI701_S002_R003_1";

    @Click(value = STATEMENT_TO_REQUIREMENT_COMPOSING_ANSWER, andWait = @Wait(value = LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE))
    STI701_S002_PostPanel clickStatementToRequirement();

    @Select(SALUTATION_COMBOBOX_RIGHT)
    STI701_S002_PostPanel selectSalutationRight(String salutation);

    @Select(SALUTATION_COMBOBOX_LEFT)
    STI701_S002_PostPanel selectSalutationLeft(String salutation);

    @CustomAction
    default STI701_S002_PostPanel checkClientName(String name) {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        Assertions.assertEquals(endpoint.getAttribute(CLIENT_NAME_INPUT, "value"), name);
        return null;
    }

    @TypeInto(STREET_DESC_NO_INPUT)
    STI701_S002_PostPanel fillStreetWithDescNo(String street);

    @TypeInto(CITY_INPUT)
    STI701_S002_PostPanel fillCity(String city);

    @TypeInto(POSTAL_CODE_INPUT)
    STI701_S002_PostPanel fillPostalCode(String postalCode);

    @TypeInto(INFLECT_CLIENT_NAME_INPUT)
    STI701_S002_PostPanel fillInflectClientName(String inflection);

    @CustomAction
    default STI701_S002_PostPanel checkOverwrittenTaskId(Harness harness) {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        Assertions.assertEquals(harness.get(TASK_ID_KEY), endpoint.getAttribute(TASK_ID_INPUT, "value"));
        return null;
    }

    @CustomAction
    default STI701_S002_PostPanel checkDateOfAcceptanceRequirement(String elementWithDate) {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        LocalDate date = LocalDate.parse(endpoint.getAttribute(elementWithDate, "value"), DateTimeFormatter.ofPattern("d.M.yyyy"));
        Assertions.assertEquals(date, LocalDate.now(), "Times are not the same");
        return null;
    }

    @Click(MM_BANK_RADIO)
    STI701_S002_EmailPanel clickMMB();
}
