package ru.yandex.autotests.direct.api.adgroups.delete;

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

import org.junit.Before;
import org.junit.BeforeClass;
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.direct.api.adgroups.AdGroupsFeatures;
import ru.yandex.autotests.direct.api.adgroups.AdGroupsLogins;
import ru.yandex.autotests.direct.db.models.jooq.ppc.enums.PhrasesAdgroupType;
import ru.yandex.autotests.directapi.apiclient.config.Semaphore;
import ru.yandex.autotests.directapi.apiclient.errors.Api5ErrorDetails;
import ru.yandex.autotests.directapi.darkside.model.CampaignsType;
import ru.yandex.autotests.directapi.model.api5.adgroups.DeleteRequestMap;
import ru.yandex.autotests.directapi.model.api5.general.ExpectedResult;
import ru.yandex.autotests.directapi.model.api5.general.IdsCriteriaMap;
import ru.yandex.autotests.directapi.model.api5.general.Notification;
import ru.yandex.autotests.directapi.rules.ApiSteps;
import ru.yandex.autotests.directapi.rules.Trashman;
import ru.yandex.qatools.allure.annotations.Description;
import ru.yandex.qatools.allure.annotations.Features;
import ru.yandex.qatools.allure.annotations.Issue;
import ru.yandex.qatools.allure.annotations.Issues;
import ru.yandex.qatools.allure.annotations.Step;
import ru.yandex.qatools.hazelcast.SemaphoreRule;

/**
 * Created by ginger on 22.06.16.
 * https://st.yandex-team.ru/TESTIRT-9520
 */
@Aqua.Test
@Features(AdGroupsFeatures.DELETE)
@Description("Группы неподдерживаемых типов не удаляются")
@Issues({@Issue("https://st.yandex-team.ru/DIRECT-46973"),
        @Issue("https://st.yandex-team.ru/DIRECT-66999")})
@RunWith(Parameterized.class)
public class DeleteNotSupportedAdGroupTypeTest {
    private static final String LOGIN = AdGroupsLogins.CLIENT;
    private static int shard;

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

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

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

    private Long adGroupId;

    @Parameterized.Parameter()
    public CampaignsType campaignsType;

    @Parameterized.Parameter(1)
    public PhrasesAdgroupType adgroupType;

    @Parameterized.Parameters(name = "campaignsType:{0}, adgroupType:{1}")
    public static Collection<Object[]> data() {
        return Arrays.asList(new Object[][]{
                {CampaignsType.MCBANNER, PhrasesAdgroupType.base},
        });
    }

    @BeforeClass
    public static void init() {
        api.userSteps.clientFakeSteps().fakeClearClientSpentUnits(LOGIN);
        shard = api.userSteps.clientFakeSteps().getUserShard(LOGIN);
    }

    @Before
    @Step("Подготовка тестовых данных")
    public void createTestData() {
        long campaignId = api.userSteps.campaignSteps().addDefaultTextCampaign();
        adGroupId = api.userSteps.adGroupsSteps().addDefaultGroup(campaignId);

        api.userSteps.campaignFakeSteps().setType(campaignId, campaignsType);
        api.userSteps.getDirectJooqDbSteps().useShard(shard).adGroupsSteps()
                .setType(adGroupId, adgroupType);
    }

    @Test
    public void deleteAdGroup() {
        api.userSteps.adGroupsSteps().shouldGetResultOnDelete(
                new DeleteRequestMap().withSelectionCriteria(new IdsCriteriaMap().withIds(adGroupId)),
                ExpectedResult.errors(new Notification(8800, Api5ErrorDetails.ADGROUP_NOT_FOUND_BY_ID, adGroupId))
        );
    }

}
