package com.ruby.shape;

import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.Paint;
import android.graphics.PixelFormat;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.facebook.react.bridge.ReadableMap;

import java.util.Objects;

public abstract class Shape extends Drawable {
    protected Paint paint;
    protected Rect rect;

    public Shape(ReadableMap map) {
        int x = map.getInt("x");
        int y = map.getInt("y");
        int width = map.getInt("width");
        int height = map.getInt("height");
        setBounds(x, y, x+width, y+height);
    }

    @Override
    public void setBounds(int left, int top, int right, int bottom) {
        super.setBounds(left, top, right, bottom);
        rect = getBounds();
    }

    @Override
    public void setBounds(@NonNull Rect bounds) {
        super.setBounds(bounds);
        rect = bounds;
    }

    @Override
    public void setAlpha(int alpha) {

    }

    @Override
    public void setColorFilter(@Nullable ColorFilter colorFilter) {

    }

    @Override
    public int getOpacity() {
        return PixelFormat.OPAQUE;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Shape)) return false;
        Shape shape = (Shape) o;
        return rect.equals(shape.rect);
    }

    @Override
    public int hashCode() {
        return Objects.hash(rect);
    }

    public void setPaint(Paint paint) {
        this.paint = paint;
    }
}
