package com.capgemini.reports.documentationobjects;

import com.capgemini.framework.teamcenter.authent.TcSession;
import com.teamcenter.soa.client.model.strong.Item;
import com.teamcenter.soa.client.model.strong.ItemRevision;

import static com.capgemini.framework.teamcenter.object.SnecmaObjectProperties.*;

/**
 * Class representing a DocNorm.
 */
public class DocNorm extends AbstractDoc {
    private static final long serialVersionUID = 8380671472697651060L;
    private final Item item;

    public DocNorm(final TcSession session, final ItemRevision itemRevision) {
        super(session, itemRevision);
        this.item = null;
    }

    public DocNorm(final TcSession session, final Item item) {
        super(session, null);
        this.item = item;
    }

    public String getItemName() {
        if (item == null) {
            return getItem().get_object_name();
        } else {
            return item.get_object_name();
        }
    }

    @Override
    public String getType() {
        if (item == null) {
            return super.getType();
        } else {
            return item.getTypeObject().getName();
        }
    }

    @Override
    public String getDocId() {
        if (item == null) {
            return super.getDocId();
        } else {
            return item.get_item_id();
        }
    }

    @Override
    public String getRevision() {
        if (item == null) {
            return super.getRevision();
        } else {
            return "";
        }
    }

    public String getDesignationEn() {
        return getMasterFormRev().getPropertyObject(PV_DESIGNATION_EN).getStringValue();
    }

    public String getTypeDocNorm() {
        return getMasterFormRev().getPropertyObject(PV_TYPE_DOC_NORM).getStringValue();
    }

    public String getIdOrigine() {
        return getMasterFormRev().getPropertyObject(PV_ID_ORIGINE).getStringValue();
    }

    public String getSensibiliteSecurite() {
        return getMasterForm().getPropertyObject(PV_SENSIBILITE_SECURITE).getStringValue();
    }

    @Override
    public <T> T accept(final IDocVisitor<T> docVisitor) {
        return docVisitor.visit(this);
    }

}
