package usda.weru.util;

import javax.measure.quantity.Energy;
import javax.measure.quantity.Volume;

import tec.uom.se.unit.MetricPrefix;
import si.uom.SI;
import javax.measure.Unit;
import javax.measure.quantity.Dimensionless;

import usda.weru.weps.fuel.EnergyPerVolume;
import usda.weru.weps.fuel.PricePerVolume;

/**
 *
 * @author josephalevin
 */
public class Units {
    
    /**
     * Unsure if these need to be of type Unit or type Quantity, the rest of the code operates like they are Unit objects
     */
    //public static final Quantity<Energy> BTU = Quantities.getQuantity(1055.05585, SI.JOULE);
    //public static final Quantity<Energy> DIESEL_US = BTU.divide(1.0 / 140000.00);
    public static final Unit<Energy> BTU = SI.JOULE.multiply(1055.05585);
    public static final Unit<Energy> DIESEL_US = BTU.divide(1.0 / 140000.00);
    public static final Unit<Energy> DIESEL_SI = MetricPrefix.KILO(SI.JOULE).divide(1.0 / 39020.00);
//    //Assign label to units
//    static {
//        //FormatUnits unitFormat = new FormatUnits();
//        final UnitFormat unitFormat = ServiceProvider.current().getUnitFormatService().getUnitFormat("EBNF");
//        //Currently unsure if quantities have labels
//        //FormatUnits.getInstance(UCUMFormat.Variant.CASE_SENSITIVE).label(DIESEL_SI, "Diesel");
//        //FormatUnits.getInstance(UCUMFormat.Variant.CASE_SENSITIVE).label(DIESEL_US, "Diesel");
//        //FormatUnits.getInstance(UCUMFormat.Variant.CASE_SENSITIVE).label(BTU, "btu");
//        unitFormat.label(DIESEL_SI, "Diesel");
//        unitFormat.label(DIESEL_US, "Diesel");
//        unitFormat.label(BTU, "btu");
//    }

    /**
     *
     * @param currency
     * @param volume
     * @return
     */
//    public static Unit<?> createPricePerVolumeUnit(Unit<Dimensionless> currency, Unit<Volume> volume) {
//        return currency.divide(volume);
//    }
    public static Unit<PricePerVolume> createPricePerVolumeUnit(Unit<Dimensionless> currency, Unit<Volume> volume) {
        return currency.divide(volume).asType(PricePerVolume.class);
    }
    /**
     *
     * @param energy
     * @param volume
     * @return
     */
//    public static Unit<?> createEnergyPerVolumeUnit(Unit<Energy> energy, Unit<Volume> volume) {
//        return energy.divide(volume);
//    }
    public static Unit<EnergyPerVolume> createEnergyPerVolumeUnit(Unit<Energy> energy, Unit<Volume> volume) {
        return energy.divide(volume).asType(EnergyPerVolume.class);
    }

//    private static class FormatUnits extends UCUMFormat {
//
////        public FormatUnits() {
////            System.out.println("Formatting units.");
////        }
//
//        @Override
//        public Unit<? extends Quantity<?>> parse(CharSequence arg0, ParsePosition arg1) throws ParserException {
//            throw new UnsupportedOperationException("Not supported.");
//        }
//
//        @Override
//        public Unit<? extends Quantity<?>> parse(CharSequence arg0) throws ParserException {
//            throw new UnsupportedOperationException("Not supported.");
//        }
//
//    }
}
