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

import com.capgemini.reports.bomlineholder.BOMLineHolder;
import com.capgemini.reports.bomlineholder.flattener.line.AbstractAltPart;
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.AbstractItemComparator;
import com.capgemini.reports.exceptions.NotSupportedException;
import com.capgemini.reports.snecmaobjects.part.AbstractPart;
import lombok.extern.slf4j.Slf4j;

/**
 * Represents The link between an Alt and a Part in its pseudo-folder.
 */
@Slf4j
public class R07AltPart extends AbstractAltPart<String, TransformerR07> implements ComparableLine {

    /**
     * builds the link between an Altenrate and a Part in its pseudo-folder.
     *
     * @param alt     the Alternate
     * @param child   the child part
     * @param counter the position of this line in the nomenclature.
     */
    public R07AltPart(final BOMLineHolder alt, final AbstractPart child, final int counter) {
        super(alt, child, 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 R07AltPart other) {
        try {
            int cmp = AbstractBomLineComparator.compareReceptors(this.getAltBL(), other.getAltBL());
            if (cmp != 0) {
                return cmp;
            }
            cmp = AbstractItemComparator.compareComponents(this.getChild(), other.getChild());
            return cmp;
        } catch (NotSupportedException e) {
            log.info("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 R07PartRfPart other) {
        return 1;
    }

}
