package com.capgemini.reports.bomlineholder.flattener.line;

import com.capgemini.framework.teamcenter.authent.TcSession;
import com.capgemini.framework.teamcenter.exceptions.KurtException;
import com.capgemini.framework.teamcenter.object.types.SnecmaObjectTypes;
import com.capgemini.reports.bomlineholder.BOMLineHolder;
import com.capgemini.reports.bomlineholder.BOMLineHolderHelper;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

import java.util.Map;

/**
 * Abstract class findAll the informations of receptor and repere.
 *
 * @param <T> the type of result to be produced: a {@link Map}, a {@link String}...
 * @param <U> a Transformer object producing results of type T
 */
@Slf4j
@Getter
public abstract class AbstractReceptorRepere<U, T> implements SnecmaLine<T, U> {

    private static final String EMPTY = "";

    private final BOMLineHolder objectTypeReceptor;
    private final BOMLineHolder repereFonctionnel;
    private final TcSession session;

    protected AbstractReceptorRepere(final TcSession session, final BOMLineHolder objectTypeReceptor, final BOMLineHolder repereFonctionnel) {
        this.session = session;
        this.objectTypeReceptor = objectTypeReceptor;
        this.repereFonctionnel = repereFonctionnel;
    }

    @Override
    public String getIDReceptor() {
        return objectTypeReceptor.getSnecmaObject().getItemId();
    }

    @Override
    public String getNameReceptor() {
        return objectTypeReceptor.getSnecmaObject().getName();
    }

    @Override
    public String getRevisionReceptor() {
        return objectTypeReceptor.getSnecmaObject().getRevisionId();
    }

    @Override
    public String getRepereName() {
        return repereFonctionnel.getSnecmaObject().getName();
    }

    @Override
    public String getRepereRevision() {
        return repereFonctionnel.getSnecmaObject().getRevisionId();
    }

    @Override
    public String getResponsableRepere() {
        try {
            if (repereFonctionnel.getSnecmaObject().isRFGeneric()) {
                return BOMLineHolderHelper.findRfAdmin(repereFonctionnel).getResponsableRepere();
            } else if (repereFonctionnel.getSnecmaObject().isRFPartOrPartAssemb()) {
                if (SnecmaObjectTypes.RF_PART_ASSEMB_REVISION.equals(repereFonctionnel.getSnecmaObject().getType())) {
                    return BOMLineHolderHelper.findRfAdminA(repereFonctionnel).getResponsableRepere();
                } else {
                    return BOMLineHolderHelper.findRfAdmin(repereFonctionnel).getResponsableRepere();
                }
            }
        } catch (KurtException e) {
            log.warn("Unable to find the correct RF Admins below Rf: " + repereFonctionnel.getSnecmaObject().getName(), e);
            return EMPTY;
        }
        return EMPTY;
    }

    @Override
    public String getIDComponent() {
        return EMPTY;
    }

    @Override
    public String getIDRevisionComponent() {
        return EMPTY;
    }

    @Override
    public String getTypeReference() {
        return EMPTY;
    }

    @Override
    public String getNameReference() {
        return EMPTY;
    }

    @Override
    public String getReferenceConceptor() {
        return EMPTY;
    }

    @Override
    public String getReferenceTransposed() {
        return EMPTY;
    }

    @Override
    public String getReferenceAssociated() {
        return EMPTY;
    }

    @Override
    public String getResponsableConception() {
        return EMPTY;
    }

    @Override
    public String getArticleGestion() {
        return EMPTY;
    }

    @Override
    public String getClassement() {
        return EMPTY;
    }

    @Override
    public String getSuiviUtilisation() {
        return EMPTY;
    }

    @Override
    public String getSuiviDureeVie() {
        return EMPTY;
    }

    @Override
    public String[] getSuppliersList() {
        return new String[0];
    }

    @Override
    public String getALT() {
        return EMPTY;
    }

    @Override
    public String getSB() {
        return EMPTY;
    }

    @Override
    public String getQuantiteCumulee() {
        return EMPTY;
    }

    @Override
    public String getPanachage() {
        return EMPTY;
    }

    @Override
    public String getQuantite() {
        return EMPTY;
    }

    @Override
    public String getSuiviMontage() {
        return EMPTY;
    }

    @Override
    public Double getMass() {
        return null;
    }

    @Override
    public String getMassUnit() {
        return EMPTY;
    }

    @Override
    public String getMaquetteInterneExterne() {
        try {
            if (repereFonctionnel.getSnecmaObject().isRFGeneric()) {
                return BOMLineHolderHelper.findRfAdmin(repereFonctionnel).getMaqIntExt();
            } else if (repereFonctionnel.getSnecmaObject().isRFPartOrPartAssemb()) {
                if (SnecmaObjectTypes.RF_PART_ASSEMB_REVISION.equals(repereFonctionnel.getSnecmaObject().getType())) {
                    return EMPTY;
                } else {
                    return BOMLineHolderHelper.findRfAdmin(repereFonctionnel).getMaqIntExt();
                }
            }
        } catch (KurtException e) {
            log.warn("Unable to find the correct RF Admins below Rf: " + repereFonctionnel.getSnecmaObject().getName(), e);
            return EMPTY;
        }
        return EMPTY;
    }

    @Override
    public String getDesignationENG() {
        return EMPTY;
    }
}
