package com.capgemini.reports.documentationobjects;

import com.capgemini.framework.teamcenter.authent.TcSession;
import com.capgemini.framework.teamcenter.object.types.SnecmaObjectTypes;
import com.teamcenter.soa.client.model.strong.Item;
import com.teamcenter.soa.client.model.strong.ItemRevision;
import lombok.extern.slf4j.Slf4j;

/**
 * Factory for all {@link AbstractDoc}s.
 */
@Slf4j
public final class DocFactory {

    private DocFactory() {
        // Nothing to do
    }

    /**
     * Builds an {@link AbstractDoc} from an {@link ItemRevision}.<br>
     */
    public static AbstractDoc build(final TcSession session, final Item doc) {
        String docType = doc.getTypeObject().getName();
        switch (docType) {
            case SnecmaObjectTypes.DOC_NORM:
                return new DocNorm(session, doc);
            case SnecmaObjectTypes.DOC_NORM_STANDARD:
                return new DocNormStandard(session, doc);
            default:
                log.warn("Unable to find the builder for doc: {}", docType);
                return null;
        }
    }

    /**
     * Builds an {@link AbstractDoc} from an {@link ItemRevision}.<br>
     */
    public static AbstractDoc build(final TcSession session, final ItemRevision docRev) {
        String docType = docRev.getTypeObject().getName();
        switch (docType) {
            case SnecmaObjectTypes.DOC_DRAWING_REVISION:
                return new DocDrawing(session, docRev);
            case SnecmaObjectTypes.DOC_GEOMETRY_REVISION:
                return new DocGeometry(session, docRev);
            case SnecmaObjectTypes.DOC_NORM_REVISION:
                return new DocNorm(session, docRev);
            case SnecmaObjectTypes.DOC_NORM_STANDARD_REVISION:
                return new DocNormStandard(session, docRev);
            case SnecmaObjectTypes.DOC_TECHNIC_REVISION:
                return new DocTechnic(session, docRev);
            default:
                log.warn("Unable to find the builder for doc: {}", docType);
                return null;
        }
    }
}
