package com.alterdekim.game.message.amf;

import lombok.*;


@Setter
@NoArgsConstructor
@AllArgsConstructor
public class AMFObject {
    @Getter
    private AMFValueType type;
    private Object value;

    public long getLong() {
        return switch (type) {
            case STRING -> Long.parseLong((String) this.value);
            case NUMBER -> ((Number) this.value).longValue();
            default -> 0L;
        };
    }

    public int getInt() {
        return switch (type) {
            case STRING -> Integer.parseInt((String) this.value);
            case NUMBER -> ((Number) this.value).intValue();
            default -> 0;
        };
    }

    public double getDouble() {
        return switch (type) {
            case STRING -> Double.parseDouble((String) this.value);
            case NUMBER -> ((Number) this.value).doubleValue();
            default -> 0;
        };
    }

    public boolean getBoolean() {
        return type == AMFValueType.BOOLEAN ? (Boolean) this.value : false;
    }

    public Object getRaw() {
        return this.value;
    }

    @Override
    public String toString() {
        return switch (this.type) {
            case STRING -> (String) this.value;
            case NULL -> "null";
            default -> this.value.toString();
        };
    }
}
