package com.iqser.red.service.persistence.management.v1.processor.migration.migrations.model.reducetext;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.iqser.red.service.persistence.service.v1.api.shared.model.redactionlog.Rectangle;

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

@Data
@AllArgsConstructor
@NoArgsConstructor
public abstract class AbstractTextContainer {

    @JsonIgnore
    protected float minX;
    @JsonIgnore
    protected float maxX;
    @JsonIgnore
    protected float minY;
    @JsonIgnore
    protected float maxY;
    @JsonIgnore
    protected String classification;
    @JsonIgnore
    protected int page;


    public abstract String getText();


    public boolean contains(AbstractTextContainer other) {

        return this.minX <= other.minX && this.maxX >= other.maxX && this.minY >= other.minY && this.maxY <= other.maxY;
    }


    public boolean contains(Rectangle other) {

        return page == other.getPage() && this.minX <= other.getTopLeft().getX() && this.maxX >= other.getTopLeft().getX() + other.getWidth() && this.minY <= other.getTopLeft()
                .getY() && this.maxY >= other.getTopLeft().getY() + other.getHeight();
    }


    @JsonIgnore
    public float getHeight() {

        return maxY - minY;
    }


    @JsonIgnore
    public float getWidth() {

        return maxX - minX;
    }

}
