package ru.yandex.autotests.directapi.dictionaries.get.positive.geoRegions;

import com.yandex.direct.api.v5.dictionaries.DictionaryNameEnum;
import com.yandex.direct.api.v5.dictionaries.GeoRegionsItem;
import com.yandex.direct.api.v5.dictionaries.GetResponse;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import ru.yandex.aqua.annotations.project.Aqua;
import ru.yandex.autotests.directapi.apiclient.config.Semaphore;
import ru.yandex.autotests.direct.utils.model.Locale;
import ru.yandex.autotests.direct.utils.model.RegionIDValues;
import ru.yandex.autotests.directapi.dictionaries.DictionariesFeatures;
import ru.yandex.autotests.directapi.dictionaries.DictionariesLogins;
import ru.yandex.autotests.directapi.model.Logins;
import ru.yandex.autotests.directapi.model.api5.dictionaries.DictionariesTextResources;
import ru.yandex.autotests.directapi.model.api5.dictionaries.GetRequestMap;
import ru.yandex.autotests.directapi.rules.ApiSteps;
import ru.yandex.autotests.directapi.rules.Trashman;
import ru.yandex.qatools.allure.annotations.Features;
import ru.yandex.qatools.allure.annotations.Issue;
import ru.yandex.qatools.allure.annotations.Title;
import ru.yandex.qatools.hazelcast.SemaphoreRule;

import java.util.Arrays;
import java.util.Collection;
import java.util.List;

import static org.hamcrest.Matchers.*;
import static ru.yandex.autotests.irt.testutils.allure.TestSteps.assertThat;
import static ru.yandex.autotests.irt.testutils.allure.TestSteps.assumeThat;

/**
 * Created by proxeter on 25.01.16.
 *
 * https://st.yandex-team.ru/TESTIRT-8316
 */
@Aqua.Test
@Title("Получение элемента словаря регионов")
@Features(DictionariesFeatures.GET)
@Issue("https://st.yandex-team.ru/DIRECT-41252")
@RunWith(Parameterized.class)
public class GetGeoRegionsDictionaryItemTest {

    private static final String LOGIN = DictionariesLogins.DICTIONARIES_LOGIN;

    @ClassRule
    public static ApiSteps api = new ApiSteps().as(LOGIN);

    @Rule
    public Trashman trashman = new Trashman(api);

    @ClassRule
    public static SemaphoreRule semaphore = Semaphore.getSemaphore();

    @Parameterized.Parameter(value = 0)
    public String locale;

    @Parameterized.Parameters(name = "{0}")
    public static Collection data() {
        return Arrays.asList(new Object[][] {
                { Locale.ENGLISH.getName() },
                { Locale.RUSSIAN.getName() },
        });
    }

    private List<GeoRegionsItem> regions;

    @Before
    public void before() {
        api.userSteps.clientFakeSteps().fakeClearClientSpentUnits(LOGIN);

        GetResponse dictionaries = api.locale(locale).userSteps.dictionariesSteps().getDictionaries(
                new GetRequestMap().withDictionaryNames(DictionaryNameEnum.GEO_REGIONS)
        );

        regions = dictionaries.getGeoRegions();

        assumeThat("получен словарь регионов", regions, hasSize(greaterThan(0)));
    }

    @Test
    @ru.yandex.qatools.allure.annotations.TestCaseId("9612")
    public void getWorldGeoRegionItem() {
        GeoRegionsItem geoRegion = new GeoRegionsItem();
        geoRegion.setGeoRegionId(0);
        geoRegion.setGeoRegionName(DictionariesTextResources.GEO_REGIONS_WORLD_NAME.text(locale));
        geoRegion.setGeoRegionType(DictionariesTextResources.GEO_REGIONS_WORLD_TYPE.text(locale));
        geoRegion.setParentId(null);

        assertThat("регион 'Мир' найден", regions, hasItem(geoRegion));
    }

    @Test
    @ru.yandex.qatools.allure.annotations.TestCaseId("9613")
    public void getCrimeaGeoRegionItem() {
        GeoRegionsItem geoRegion = new GeoRegionsItem();
        geoRegion.setGeoRegionId(RegionIDValues.CRIMEA.getId());
        geoRegion.setGeoRegionName(DictionariesTextResources.GEO_REGIONS_CRIMEA_NAME.text(locale));
        geoRegion.setGeoRegionType(DictionariesTextResources.GEO_REGIONS_CRIMEA_TYPE.text(locale));
        geoRegion.setParentId(0L);

        assertThat("регион 'Крым' найден", regions, hasItem(geoRegion));
    }

}
