package com.capgemini.reports.definition.r07report.data.extractor.lines;

import com.capgemini.framework.teamcenter.authent.TcSession;
import com.capgemini.reports.bomlineholder.BOMLineHolder;
import com.capgemini.reports.bomlineholder.flattener.line.AbstractPartRfPart;
import com.capgemini.reports.definition.r07report.data.TransformerR07;
import com.capgemini.reports.definition.r07report.data.filter.comparators.AbstractBomLineComparator;
import com.capgemini.reports.definition.r07report.data.filter.comparators.rf.RfComparator;
import com.capgemini.reports.exceptions.NotSupportedException;
import lombok.extern.slf4j.Slf4j;

/**
 * Represents a classical 'triplet' between a Part, a Rf Part and a Part.
 */
@Slf4j
public class R07PartRfPart extends AbstractPartRfPart<String, TransformerR07> implements ComparableLine {


    /**
     * Builds a classical 'triplet' between a Part, a Rf Part and a Part.
     *
     * @param partReceptor    a {@link BOMLineHolder}
     * @param rfPartComponent a {@link BOMLineHolder}
     * @param partComponent   a {@link BOMLineHolder}
     * @param counter         the position of the line in the nomenclature.
     */
    public R07PartRfPart(final TcSession session, final BOMLineHolder partReceptor, final BOMLineHolder rfPartComponent, final BOMLineHolder partComponent,
                         final int counter) {
        super(session, partReceptor, rfPartComponent, partComponent, counter);
    }

    @Override
    public String transform(final TransformerR07 transformer) {
        return transformer.makeIdentifier(this);
    }

    @Override
    public int compareLineContent(final ComparableLine other) {
        return other.compareContent(this);
    }

    @Override
    public int compareContent(final R07PartRfPart other) {
        try {
            int cmp = AbstractBomLineComparator.compareReceptors(this.getPartReceptorBL(), other.getPartReceptorBL());
            if (cmp == 0) {
                cmp = RfComparator.compareRf(this.getRfPartComponentBL(), other.getRfPartComponentBL());
                if (cmp == 0) {
                    cmp = AbstractBomLineComparator.compareComponents(this.getPartComponentBL(), other.getPartComponentBL());
                }
            }
            return cmp;
        } catch (NotSupportedException e) {
            log.warn("Failed object comparison", e);
            return 1;
        }
    }

    @Override
    public int compareContent(final R07Quad other) {
        return 1;
    }

    @Override
    public int compareContent(final R07ReceptorLine other) {
        return 1;
    }

    @Override
    public int compareContent(final R07ProductGeneric other) {
        return 1;
    }

    @Override
    public int compareContent(final R07AltPart other) {
        return 1;
    }
}
