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.AbstractProductGeneric;
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 Product - Generic line for R07 report.
 */
@Slf4j
public class R07ProductGeneric extends AbstractProductGeneric<String, TransformerR07> implements ComparableLine {

    /**
     * Builds a Product - Generic line for the R07 report.
     *
     * @param productReceptor    a {@link BOMLineHolder}
     * @param genericComponent   a {@link BOMLineHolder}
     * @param rfGenericComponent a {@link BOMLineHolder}
     * @param counter            the position of this line in the Bom.
     */
    public R07ProductGeneric(final TcSession session, final BOMLineHolder productReceptor, final BOMLineHolder genericComponent, final BOMLineHolder rfGenericComponent,
                             final int counter) {
        super(session, productReceptor, genericComponent, rfGenericComponent, 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) {
        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) {
        try {
            int cmp = AbstractBomLineComparator.compareReceptors(this.getProductReceptorBL(), other.getProductReceptorBL());
            if (cmp == 0) {
                cmp = RfComparator.compareRf(this.getRfGenericComponentBL(), other.getRfGenericComponentBL());
                if (cmp == 0) {
                    cmp = AbstractBomLineComparator.compareComponents(this.getGenericComponentBL(), other.getGenericComponentBL());
                }
            }
            return cmp;
        } catch (NotSupportedException e) {
            log.warn("Failed object comparison", e);
            return 1;
        }
    }

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