package com.iqser.red.service.persistence.service.v1.api.shared.model.annotations;

import com.iqser.red.service.persistence.service.v1.api.shared.model.redactionlog.Point;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Rectangle {

    private Point topLeft = new Point();
    private float width;
    private float height;
    private int page;


    @Builder
    public static Rectangle createRectangle(float topLeftX, float topLeftY, float width, float height, int page) {

        return new Rectangle(topLeftX, topLeftY, width, height, page);
    }


    public Rectangle(float topLeftX, float topLeftY, float width, float height, int page) {

        topLeft.setX(topLeftX);
        topLeft.setY(topLeftY);
        this.width = width;
        this.height = height;
        this.page = page;
    }


    public float getTopLeftX() {

        return topLeft != null ? topLeft.getX() : 0f;
    }


    public float getTopLeftY() {

        return topLeft != null ? topLeft.getY() : 0f;
    }


    public void setTopLeftX(float topLeftX) {

        if (topLeft == null) {
            topLeft = new Point();
        }
        topLeft.setX(topLeftX);

    }


    public void setTopLeftY(float topLeftY) {

        if (topLeft == null) {
            topLeft = new Point();
        }
        topLeft.setY(topLeftY);
    }

}
