package usda.weru.gis.data;

import org.geotools.data.FeatureSource;
import org.opengis.feature.Feature;

/**
 *
 * @author Joseph Levin <joelevin@weru.ksu.edu>
 */
public class SoilMapUnitLookup extends AbstractLookup<SoilMapUnit> {

    private static final String COLUMN_AREASYMBOL = "AREASYMBOL";
    private static final String COLUMN_MUKEY = "MUKEY";
    private static final String COLUMN_MUSYM = "MUSYM";

    /**
     *
     * @param source
     * @param feature
     * @return
     */
    @Override
    protected SoilMapUnit create(FeatureSource<?, ?> source, Feature feature) {
        String area = getValue(feature, COLUMN_AREASYMBOL, String.class);
        String mukeyString = getValue(feature, COLUMN_MUKEY, String.class);
        String musymString = getValue(feature, COLUMN_MUSYM, String.class);

        long mukey = Long.parseLong(mukeyString);
        long musyL = Long.parseLong(musymString);

        return new SoilMapUnit(area, mukey, musyL);
    }

    /**
     *
     * @return
     */
    @Override
    protected Class<SoilMapUnit> getSupportedClass() {
        return SoilMapUnit.class;
    }

    @Override
    protected boolean supports(FeatureSource<?, ?> source) {
        if (hasColumn(source, COLUMN_AREASYMBOL, String.class)) {
            if (hasColumn(source, COLUMN_MUKEY, String.class)) {
                if (hasColumn(source, COLUMN_MUSYM, String.class)) {
                    return true;
                }

            }
        }
        return false;
    }

}
