package com.capgemini.framework.teamcenter.object.pom.workspace.bom.product;

import com.capgemini.framework.teamcenter.authent.TcSession;
import com.capgemini.framework.teamcenter.object.pom.workspace.TcItem;
import com.capgemini.framework.teamcenter.object.pom.workspace.bom.TcBomObject;
import com.teamcenter.services.strong.cad._2007_01.StructureManagement.RevisionRuleEntryProps;
import com.teamcenter.services.strong.cad._2013_05.StructureManagement.CreateWindowsInfo2;
import com.teamcenter.soa.client.model.ModelObject;
import com.teamcenter.soa.client.model.strong.Item;
import com.teamcenter.soa.client.model.strong.ItemRevision;

import java.util.ArrayList;
import java.util.List;

public class TcProduct implements TcItem, TcBomObject {
  private final TcSession session;
  private final Item item;

  public TcProduct(final TcSession session, final Item item) {
    this.session = session;
    this.item = item;
  }

  @Override
  public void addInfo(final CreateWindowsInfo2 createWindowsInfo2) {
    createWindowsInfo2.item = item;
  }

  public void addInfo(final RevisionRuleEntryProps revisionRulesProps) {
    revisionRulesProps.endItem = item;
  }

  public List<TcProductRevision> revisions() {
    List<TcProductRevision> revisions = new ArrayList<>();
    session.loadProperties(item, "revision_list");
    ModelObject[] revisionObjects = item.get_revision_list();
    session.loadProperties(revisionObjects);
    for (ModelObject revision : revisionObjects) {
      revisions.add(new TcProductRevision(session, (ItemRevision) revision));
    }
    return revisions;
  }
}
