package com.capgemini.reports.definition.r07report.data.filter.comparators.rf;

import com.capgemini.reports.bomlineholder.BOMLineHolder;
import com.capgemini.reports.snecmaobjects.admin.RFAdminRevision;
import lombok.extern.slf4j.Slf4j;

/**
 * Compares two RF Generics together.
 */
@Slf4j
public class RfGenericComparator extends RfComparator {

    private static final long serialVersionUID = 8420569609216039442L;

    RfGenericComparator() {
    }

    @Override
    public int compare(final BOMLineHolder thisRfBL, final BOMLineHolder otherRfBL) {
        // Bowse children for RF Admin
        RFAdminRevision thisRfAdmin = findRfAdmin(thisRfBL);
        RFAdminRevision otherRfAdmin = findRfAdmin(otherRfBL);
        if (thisRfAdmin == null || otherRfAdmin == null) {
            if (thisRfAdmin == null && otherRfAdmin == null) {
                log.warn("No RF Admin found below both compared RF Generics: " + thisRfBL.getSnecmaObject().getName() + " / "
                        + otherRfBL.getSnecmaObject().getName());
                // No difference, then!
                return 0;
            } else {
                log.warn("No RF Admin found below one of the compared RF Generics: " + thisRfBL.getSnecmaObject().getName() + " / "
                        + otherRfBL.getSnecmaObject().getName());
                return 1; // Diff found
            }
        }
        return safeCmp(thisRfAdmin.getResponsableRepere(), otherRfAdmin.getResponsableRepere());
    }
}
