package com.ctpodp.objects.fromReact;

import android.graphics.Color;
import android.util.Log;

import com.ctpodp.ReactUtilities;
import com.jibestream.jmapandroidsdk.styles.JStyle;

import org.json.JSONException;

public class ObjectStyle {
  public String color;
  public Double alpha;
  public String stroke;
  public Double strokeWidth;
  public Double strokeAlpha;

  public ObjectStyle(String color, Double alpha, String stroke, Double strokeWidth, Double strokeAlpha) {
    this.color = color;
    this.alpha = alpha;
    this.stroke = stroke;
    this.strokeWidth = strokeWidth;
    this.strokeAlpha = strokeAlpha;
  }

  public static JStyle getJStyle(ObjectStyle style) {
    JStyle jStyle = new JStyle();
    if (style.color != null) {
      try {
        jStyle.setColor(Color.parseColor(style.color));
      }
      catch (IllegalArgumentException ignored) {}
    }
    if (style.stroke != null) {
      try {
        jStyle.setStrokeColor(Color.parseColor(style.stroke));
      }
        catch (IllegalArgumentException ignored) {}
      }
    if (style.strokeWidth != null) {
      jStyle.setStrokeWidth(style.strokeWidth.floatValue());
    }
    if (style.strokeAlpha != null) {
      jStyle.setStrokeAlpha(Math.round(style.strokeAlpha.floatValue() * 255));
    }
    if (style.alpha != null) {
      jStyle.setAlpha(Math.round(style.alpha.floatValue() * 255));
    }
    return jStyle;
  }
}
