class Transformers {

   @SuppressWarnings("unchecked")
   static void addColorAttrs(Model m, ImmutableMap.Builder<String, Object> attrs, Map<String, Object> params) {
      if(params == null) {
         params = ImmutableMap.of();
      }

      GoogleColor color = new GoogleColor((Map<String, Object>) params.get(Commands.ColorAbsolute.arg_color));

      if(color.getTemperature() != null) {
         assertCapability(m, ColorTemperatureCapability.NAMESPACE);
      }

      if(color.getSpectrumRGB() != null) {
         assertCapability(m, ColorCapability.NAMESPACE);
      }

      if(color.getTemperature() == null && color.getSpectrumRGB() == null) {
         throw new ErrorEventException(Constants.Error.VALUE_OUT_OF_RANGE,
               Commands.ColorAbsolute.arg_color + " must have either " + GoogleColor.ATTR_TEMPERATURE + " or " + GoogleColor.ATTR_SPECTRUMRGB);
      }

      if(color.getTemperature() != null) {
         assertCapability(m, ColorTemperatureCapability.NAMESPACE);
         Integer min = ColorTemperatureModel.getMincolortemp(m, Constants.Defaults.COLOR_TEMPERATURE_MIN);
         Integer max = ColorTemperatureModel.getMaxcolortemp(m, Constants.Defaults.COLOR_TEMPERATURE_MAX);
         if((min != null && color.getTemperature() < min) || (max != null && color.getTemperature() > max)) {
            throw new ErrorEventException(Constants.Error.VALUE_OUT_OF_RANGE,
                  GoogleColor.ATTR_TEMPERATURE + " must be between " + min + " and " + max);
         }
         Integer colorTemp = color.getTemperature();
         if(!Objects.equals(LightModel.getColormode(m), LightCapability.COLORMODE_COLORTEMP)) {
            attrs.put(LightCapability.ATTR_COLORMODE, LightCapability.COLORMODE_COLORTEMP);
         }
         if(!Objects.equals(ColorTemperatureModel.getColortemp(m), colorTemp)) {
            attrs.put(ColorTemperatureCapability.ATTR_COLORTEMP, color.getTemperature());
         }
      } else if(color.getSpectrumRGB() != null) {
         assertCapability(m, ColorCapability.NAMESPACE);
         if(color.getSpectrumRGB() < Constants.Defaults.COLOR_RGB_MIN || color.getSpectrumRGB() > Constants.Defaults.COLOR_RGB_MAX) {
            throw new ErrorEventException(Constants.Error.VALUE_OUT_OF_RANGE, GoogleColor.ATTR_SPECTRUMRGB + " must be between 0 and 16777215");
         }
         Colors.HSB hsb = new Colors.RGB(color.getSpectrumRGB()).toHSB();

         if(!Objects.equals(LightModel.getColormode(m), LightCapability.COLORMODE_COLOR)) {
            attrs.put(LightCapability.ATTR_COLORMODE, LightCapability.COLORMODE_COLOR);
         }
         if(!Objects.equals(ColorModel.getHue(m), hsb.hue())) {
            attrs.put(ColorCapability.ATTR_HUE, hsb.hue());
         }
         if(!Objects.equals(ColorModel.getSaturation(m), hsb.saturationPercent())) {
            attrs.put(ColorCapability.ATTR_SATURATION, hsb.saturationPercent());
         }
         if(m.supports(DimmerCapability.NAMESPACE) && !Objects.equals(DimmerModel.getBrightness(m), hsb.brightnessPercent())) {
            attrs.put(DimmerCapability.ATTR_BRIGHTNESS, hsb.brightnessPercent());
         }
      }
   }

   private  Transformers();

}