package com.capgemini.reports.snecmaobjects;

import com.capgemini.framework.teamcenter.authent.TcSession;
import com.capgemini.reports.exceptions.NotSupportedException;
import com.capgemini.reports.snecmaobjects.admin.RFAdminAGRevision;
import com.capgemini.reports.snecmaobjects.admin.RFAdminAPRevision;
import com.capgemini.reports.snecmaobjects.admin.RFAdminARevision;
import com.capgemini.reports.snecmaobjects.admin.RFAdminRevision;
import com.capgemini.reports.snecmaobjects.descriptif.DescriptifRevision;
import com.capgemini.reports.snecmaobjects.generic.*;
import com.capgemini.reports.snecmaobjects.mockup.MockupRevision;
import com.capgemini.reports.snecmaobjects.part.*;
import com.capgemini.reports.snecmaobjects.product.ProductRevision;
import com.capgemini.reports.snecmaobjects.rf.RFGenericRevision;
import com.capgemini.reports.snecmaobjects.rf.RFPartAssembRevision;
import com.capgemini.reports.snecmaobjects.rf.RFPartRevision;
import com.capgemini.reports.snecmaobjects.supermodel.SuperModelRevision;
import com.teamcenter.soa.client.model.strong.Item;
import com.teamcenter.soa.client.model.strong.ItemRevision;

import static com.capgemini.framework.teamcenter.object.types.SnecmaObjectTypes.*;

/**
 * Factory used for create a structured SnecmaObject (set as null by default).
 */
public class SnecmaObjectFactory {

    protected SnecmaObjectFactory() {
        // Nothing to do, just making this private
    }

    /**
     * Build an object from an {@link Item}.
     */
    public static AbstractGeneric build(final TcSession session, final Item item) throws NotSupportedException {
        switch (item.getTypeObject().getName()) {
            case GENERIC:
                return new Generic(session, item);
            case GENERIC_ASSEMB:
                return new GenericAssemb(session, item);
            default:
                throw new NotSupportedException("Expected ObjectType was not created, 'type' property was not available!");
        }
    }

    /**
     * Factory which create the structure of the SnecmaObjects from an {@link ItemRevision}.
     */
    public static AbstractSnecmaObject build(final TcSession session, final ItemRevision itemRevision)
            throws NotSupportedException {
        switch (itemRevision.getTypeObject().getName()) {
            case ALTERNATE_REVISION:
                return new AlternateRevision(session, itemRevision);
            case DESCRIPTIF_REVISION:
                return new DescriptifRevision(session, itemRevision);
            case DET_REVISION:
                return new DETRevision(session, itemRevision);
            case GENERIC_ASSEMB_REVISION:
                return new GenericAssembRevision(session, itemRevision);
            case GENERIC_REVISION:
                return new GenericRevision(session, itemRevision);
            case SUPERMODEL_REVISION:
                return new SuperModelRevision(session, itemRevision);
            case MOCKUP_REVISION:
                return new MockupRevision(session, itemRevision);
            case PART_AERO_REVISION:
                return new PartAeroRevision(session, itemRevision);
            case PART_ASSEMB_REVISION:
                return new PartAssembRevision(session, itemRevision);
            case PART_MAT_REVISION:
                return new PartMatRevision(session, itemRevision);
            case PART_NO_AERO_REVISION:
                return new PartNoAeroRevision(session, itemRevision);
            case PRODUCT_REVISION:
                return new ProductRevision(session, itemRevision);
            case RF_ADMIN_AG_REVISION:
                return new RFAdminAGRevision(session, itemRevision);
            case RF_ADMIN_AP_REVISION:
                return new RFAdminAPRevision(session, itemRevision);
            case RF_ADMIN_A_REVISION:
                return new RFAdminARevision(session, itemRevision);
            case RF_ADMIN_REVISION:
                return new RFAdminRevision(session, itemRevision);
            case RF_GENERIC_REVISION:
                return new RFGenericRevision(session, itemRevision);
            case RF_PART_ASSEMB_REVISION:
                return new RFPartAssembRevision(session, itemRevision);
            case RF_PART_REVISION:
                return new RFPartRevision(session, itemRevision);
            case STANDARD_REVISION:
                return new StandardRevision(session, itemRevision);
            default:
                throw new NotSupportedException("Expected ObjectType was not created, 'type' property was not available!");
        }
    }
}
