package com.capgemini.framework.teamcenter;

import com.teamcenter.soa.client.model.Type;

import java.util.Arrays;
import java.util.regex.Pattern;

/** Class regrouping all the used type of Teamcenter Revision objects. */
public class TeamcenterObjectTypes {

    protected TeamcenterObjectTypes() {
        // Move along, nothing to see
    }

    // Some more frequent suffixes
    protected static final String REVISION = " Revision";
    protected static final String MASTER = " Master";

    /** The WokspaceObject type. */
    public static final String WORSKPACE_OBJECT = "WorkspaceObject";
    /** The Teamcenter type for a ReleaseStatus. */
    public static final String RELEASE_STATUS = "ReleaseStatus";
    /** The Teamcenter Item Revision. */
    public static final String ITEM_REVISION = "ItemRevision";
    /** The Teamcenter type for an EPMTask (workflow task). */
    public static final String EPM_TASK = "EPMTask";
    /** The Teamcenter type for an EPMPerformSignoffTask (workflow task). */
    public static final String EPM_PERFORM_SIGNOFF_TASK = "EPMPerformSignoffTask";
    /** The Teamcenter type for an EPMDoTask (workflow task). */
    public static final String EPM_DO_TASK = "EPMDoTask";
    /** The Teamcenter type for a Signoff (Action of a User on a task). */
    public static final String SIGNOFF = "Signoff";
    /** The Teamcenter type for a User. */
    public static final String USER = "User";
    /** The Teamcenter type for a Person. */
    public static final String PERSON = "Person";
    /** The Teamcenter type for a Change Item Revision. */
    public static final String CHANGE_ITEM_REVISION = "ChangeItemRevision";
    /** The Teamcenter type for a Change Request Revision. */
    public static final String CHANGE_REQUEST_REVISION = "ChangeRequestRevision";
    /** The Teamcenter type for a Change Notice Revision. */
    public static final String CHANGE_NOTICE_REVISION = "ChangeNoticeRevision";
    /** The Teamcenter type for a mockup. */
    public static final String MOCKUP = "Mockup";
    /** The Teamcenter type for a mockup revision. */
    public static final String MOCKUP_REVISION = MOCKUP + REVISION;
    /** The Teamcenter type for a mockup revision. */
    public static final String MOCKUP_REVISION_MASTER = MOCKUP + REVISION + MASTER;
    /** Link from Item to Dataset. */
    public static final String IMAN_SPECIFICATION = "IMAN_specification";
    /** Link from Part PV to Fiche Article. */
    public static final String IMAN_REQUIREMENT = "IMAN_requirement";
    /** Link from Part PV to Fiche Article. */
    public static final String IMAN_REFERENCE = "IMAN_reference";

    /**
     * Returns <code>true</code> if the provided object type String matches a provided item type.
     * 
     * @param objectType the String describing the object type to be tested
     * @param authorizedTypes a series of authorized String Types
     * @return <code>true</code> if the object type matches any of the provided types, <code>false</code> otherwise
     */
    public static boolean isA(final String objectType, final String... authorizedTypes) {
        for (String type : authorizedTypes) {
            if (Pattern.matches("^(" + type + ")$", objectType)) {
                return true;
            }
        }
        return false;
    }

    /**
     * Verify (recursively) if the candidate {@link Type} is a type (or super type of) the Tc target Class.
     * 
     * @param targetClass the target class name
     * @param candidate the candidate Tc {@link Type}
     * @return true if any of the super types of the candidate matches the target class name
     */
    public static boolean isRecursively(String targetClass, Type candidate) {
        return Arrays.asList(candidate.getClassNameHierarchy()).contains(targetClass);
    }

}
