package com.capgemini.reports.teamcenter.queries.saved;

import com.capgemini.framework.teamcenter.exceptions.NoTeamcenterConnectionException;
import com.capgemini.framework.teamcenter.policies.PolicyLocation;
import com.capgemini.reports.AbstractTeamcenterTest;
import com.teamcenter.schemas.soa._2006_03.exceptions.ServiceException;
import com.teamcenter.soa.client.model.Property;
import com.teamcenter.soa.client.model.strong.ItemRevision;
import lombok.extern.slf4j.Slf4j;
import org.junit.Assert;
import org.junit.Test;

import java.util.List;

@Slf4j
public class ChangeRequestQueryTest extends AbstractTeamcenterTest {
    private static final String CHANGE_ID = "R201-012";

    @Test
    public void changeRequestQueryTest() throws NoTeamcenterConnectionException {
        List<ItemRevision> list = new ChangeRequestQuery(getSession()).searchID(CHANGE_ID).findAll();
        Assert.assertNotNull(list);
        Assert.assertFalse(list.isEmpty());
        log.info("{} ChangeRequest found with matching ID ({})", list.size(), CHANGE_ID);
        for (ItemRevision itemRev : list) {
            log.info(" + UID={}\tID={}\tRev={}", itemRev.getUid(), itemRev.get_item_id(), itemRev.get_item_revision_id());
        }
    }

    @Test
    public void changeRequestTypeModification() throws ServiceException, NoTeamcenterConnectionException {
        List<ItemRevision> list = new ChangeRequestQuery(getSession()).searchID(CHANGE_ID).findAll();
        Assert.assertNotNull(list);
        Assert.assertFalse(list.isEmpty());
        log.info("{} ChangeRequest found with matching ID ({})", list.size(), CHANGE_ID);
        for (ItemRevision itemRev : list) {
            Property prop = itemRev.getPropertyObject("pv4_type_modification");
            log.info(" + UID={}\tID={}\tRev={}", itemRev.getUid(), itemRev.get_item_id(), itemRev.get_item_revision_id());
            log.info("   -> ALL = {}", prop.getStringValue());
            log.info("   ->  FR = {}", prop.getDisplayableValue());
        }
    }

    @Override
    public PolicyLocation getPropertyPolicyIdentifier() {
        return R07_POLICY_FULL;
    }

}
