package ru.yandex.autotests.direct.api.ads.resume;

import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;

import ru.yandex.aqua.annotations.project.Aqua;
import ru.yandex.autotests.direct.api.ads.AdsFeatures;
import ru.yandex.autotests.direct.api.ads.AdsLogins;
import ru.yandex.autotests.directapi.apiclient.config.ProtocolType;
import ru.yandex.autotests.directapi.apiclient.config.Semaphore;
import ru.yandex.autotests.directapi.apiclient.errors.Api5Error;
import ru.yandex.autotests.directapi.apiclient.errors.Api5ErrorDetailsJava;
import ru.yandex.autotests.directapi.model.api5.ads.ResumeRequestMap;
import ru.yandex.autotests.directapi.model.api5.general.ExpectedResult;
import ru.yandex.autotests.directapi.model.api5.general.IdsCriteriaMap;
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.hazelcast.SemaphoreRule;

import static org.apache.commons.lang3.StringUtils.capitalize;

/**
 * Created by pavryabov on 16.04.15.
 * https://st.yandex-team.ru/TESTIRT-5025
 */
@Aqua.Test
@Features(AdsFeatures.RESUME)
@Description("проверка SOAP")
@Issue("https://st.yandex-team.ru/DIRECT-34573")
public class AdsResumeSOAPTest {

    @ClassRule
    public static ApiSteps api = new ApiSteps().protocol(ProtocolType.SOAP).version(104).as(AdsLogins.CLIENT);

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

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

    private static final String RESUME_REQUEST = "ResumeRequest";
    static Long adId;

    @BeforeClass
    public static void initTest() {
        api.userSteps.clientFakeSteps().fakeClearClientSpentUnits(AdsLogins.CLIENT);
        Long campaignId = api.userSteps.campaignSteps().addDefaultTextCampaign(AdsLogins.CLIENT);
        Long adGroupId = api.userSteps.adGroupsSteps().addDefaultGroup(campaignId);
        adId = api.userSteps.adsSteps().addDefaultTextAd(adGroupId);
        api.userSteps.bannersFakeSteps().makeBannersStopped(adId);
    }

    @Test
    public void successResumeTest() {
        api.userSteps.adsSteps()
                .shouldGetResultOnResume(new IdsCriteriaMap().withIds(adId), ExpectedResult.success(adId));
    }

    @Test
    public void emptyRequest() {
        api.userSteps.adsSteps().expectErrorOnAdsResume(new ResumeRequestMap(),
                new Api5Error(8000, Api5ErrorDetailsJava.MISSING_PARAMETER_VALUE,
                        capitalize(ResumeRequestMap.SELECTION_CRITERIA)));
    }

    @Test
    @Issue("DIRECT-88268")
    public void emptySelectionCriteria() {
        api.userSteps.adsSteps().expectErrorOnAdsResume(
                new ResumeRequestMap().withSelectionCriteria(new IdsCriteriaMap().withIds()),
                new Api5Error(8000, Api5ErrorDetailsJava.MISSING_PARAMETER_VALUE,
                        capitalize(ResumeRequestMap.SELECTION_CRITERIA)));
    }
}
