package com.knecon.fforesight.service.layoutparser.processor.model.text;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;

import lombok.Getter;

@Getter
public enum TextDirection {
    ZERO(0f),
    QUARTER_CIRCLE(90f),
    HALF_CIRCLE(180f),
    THREE_QUARTER_CIRCLE(270f);

    public static final String VALUE_STRING_SUFFIX = "°";

    @JsonValue
    private final float degrees;
    private final float radians;


    TextDirection(float degreeValue) {

        degrees = degreeValue;
        radians = (float) Math.toRadians(degreeValue);
    }


    @Override
    public String toString() {

        return degrees + VALUE_STRING_SUFFIX;
    }


    @JsonCreator(mode = JsonCreator.Mode.DELEGATING)
    public static TextDirection fromDegrees(float degrees) {

        for (var dir : TextDirection.values()) {
            if (degrees == dir.degrees) {
                return dir;
            }
        }

        throw new IllegalArgumentException(String.format("A value of %f is not supported by TextDirection", degrees));
    }
}
