package ru.yandex.autotests.directapi.changes.checkcampaigns;

import com.yandex.direct.api.v5.changes.CampaignChangesItem;
import com.yandex.direct.api.v5.changes.CheckCampaignsResponse;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;

import ru.yandex.aqua.annotations.project.Aqua;
import ru.yandex.autotests.direct.utils.tags.TagDictionary;
import ru.yandex.autotests.directapi.apiclient.config.Semaphore;
import ru.yandex.autotests.directapi.changes.ChangesFeatures;
import ru.yandex.autotests.directapi.model.Logins;
import ru.yandex.autotests.directapi.model.api5.changes.CampaignChangesItemMap;
import ru.yandex.autotests.directapi.model.api5.changes.CheckCampaignsRequestMap;
import ru.yandex.autotests.directapi.rules.ApiSteps;
import ru.yandex.autotests.directapi.rules.Trashman;
import ru.yandex.qatools.Tag;
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.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.not;
import static ru.yandex.autotests.irt.testutils.allure.TestSteps.assertThat;
import static ru.yandex.autotests.irt.testutils.beandiffer.BeanDifferMatcher.beanDiffer;

/**
 * Created by ginger on 31.03.15.
 * https://st.yandex-team.ru/TESTIRT-4917
 */
@Aqua.Test
@Features(ChangesFeatures.CHECK_CAMPAIGNS)
@Issue("https://st.yandex-team.ru/DIRECT-35862")
@Description("Проверка доступа ролей к методу.")
@Tag(TagDictionary.TRUNK)
public class RolesAccessNegativeTest {
    public String subClient = Logins.SUBCLIENT_CAMPAIGNS;
    @ClassRule
    public static ApiSteps api = new ApiSteps().as(Logins.AGENCY_1_CAMPAIGNS);

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

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

    @Before
    public void setUp() {
        api.userSteps.changesSteps().setUseCampAggregatedLastChange(false);
    }

    @Test
    @ru.yandex.qatools.allure.annotations.TestCaseId("3507")
    public void callChangesCheckCampaigns(){
        String timestamp = api.userSteps.changesSteps().getTimestamp(subClient);
        Long campaignId = api.userSteps.campaignSteps().addDefaultTextCampaign(subClient);
        Long adGroupId = api.userSteps.adGroupsSteps().addDefaultGroup(campaignId, subClient);
        api.userSteps.adsSteps().addDefaultTextAd(adGroupId, subClient);
        CheckCampaignsResponse actualCampaignsResponse =
                api.userSteps.changesSteps().changesCheckCampaigns(
                        new CheckCampaignsRequestMap()
                                .withTimestamp(timestamp),
                        Logins.SUBCLIENT_CAMPAIGNS
                );
        CampaignChangesItemMap expectedCampaignItems = new CampaignChangesItemMap()
                .withCampaignId((long) campaignId);
        assertThat("вернулись корректные значения",
                actualCampaignsResponse.getCampaigns(),
                not(hasItem(beanDiffer((CampaignChangesItem) expectedCampaignItems.getBean()))));
                 //ToDO: уточнить можно ли упаковывать во что-нить биндиффер, кажется была такая бага
    }


}
