package com.capgemini.reports.snecmaobjects.supermodel;

import com.capgemini.framework.teamcenter.authent.TcSession;
import com.capgemini.reports.snecmaobjects.AbstractSnecmaObject;
import com.teamcenter.soa.client.model.strong.ItemRevision;
import lombok.EqualsAndHashCode;

import java.util.regex.Pattern;

import static com.capgemini.framework.teamcenter.object.SnecmaObjectProperties.PV_DESIGNATION_EN;
import static com.capgemini.framework.teamcenter.object.SnecmaObjectProperties.PV_RESPONSABLE_CONCEPTION;


/**
 * Abstract Class representing a SuperModel.
 */
@EqualsAndHashCode(callSuper = true)
public abstract class AbstractSuperModelRevision extends AbstractSnecmaObject implements Comparable<com.capgemini.reports.snecmaobjects.supermodel.AbstractSuperModelRevision> {
    private static final long serialVersionUID = -190379543546189856L;

    /**
     * This pattern identify a {@link SuperModelRevision} id.
     **/
    private static final Pattern REGEX_PATTERN_FOR_GENERIC_REVISION = Pattern.compile("^[A-Z]");

    public AbstractSuperModelRevision(final TcSession session, final ItemRevision itemRevision) {
        super(session, itemRevision);
    }

    /**
     * Return true if the id correspond to a {@link SuperModelRevision} id.<br/>
     */
    public static boolean isSuperModelRevision(final String genId) {
        return REGEX_PATTERN_FOR_GENERIC_REVISION.matcher(genId).find();
    }

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

    public String getResponsableConception() {
        return getMasterFormRev().getPropertyObject(PV_RESPONSABLE_CONCEPTION).getStringValue();
    }

    @Override
    public int compareTo(final com.capgemini.reports.snecmaobjects.supermodel.AbstractSuperModelRevision other) {
        int compareID = this.getItemId().compareTo(other.getItemId());
        if (compareID != 0) {
            return compareID; // Different ID
        } else {
            return this.getRevisionId().compareTo(other.getRevisionId());
        }
    }

    @Override
    public boolean isSuperModel() {
        return true;
    }
}
