package click.kamil.springstatemachineexporter.ast.app;

import lombok.Getter;
import org.eclipse.jdt.core.dom.Expression;
import org.eclipse.jdt.core.dom.StringLiteral;

@Getter
public class QuotedExpression {
    private final Expression expression;

    private QuotedExpression(Expression expression) {
        this.expression = expression;
    }

    public String toStringWithoutQuotes() {
        if (expression == null)
            return null;
        if (expression instanceof StringLiteral sl) {
            return sl.getLiteralValue();
        }
        return stripQuotes(expression.toString());
    }

    public static String stripQuotes(String s) {
        if (s == null)
            return null;
        return s.replaceAll("^\"|\"$", "");
    }

    public static QuotedExpression of(Expression expression) {
        return new QuotedExpression(expression);
    }

    public static QuotedExpression of(Object obj) {
        if (obj instanceof Expression expr) {
            return new QuotedExpression(expr);
        }
        return null;
    }
} 
