package com.ruoyi.interfaces.domain;

import com.ruoyi.common.utils.StringUtils;

import java.io.Serializable;

public class PtServiceParam extends PtServiceParamKey implements Serializable {
    private String srvId;
    private String paramCode;

    private String paramName;

    private String paramType;

    private String paramValue;

    private String paramFormat;

    private String paramNote;

    private Integer sort;

    public Integer getSort() {
        return sort;
    }

    public void setSort(Integer sort) {
        this.sort = sort;
    }

    private static final long serialVersionUID = 1L;

    @Override
    public String getSrvId() {
        return srvId;
    }

    @Override
    public void setSrvId(String srvId) {
        this.srvId = srvId;
    }

    @Override
    public String getParamCode() {
        return paramCode;
    }

    @Override
    public void setParamCode(String paramCode) {
        this.paramCode = paramCode;
    }

    public String getParamName() {
        return paramName;
    }

    public void setParamName(String paramName) {
        this.paramName = paramName == null ? null : paramName.trim();
    }

    public String getParamType() {
        return paramType;
    }

    public void setParamType(String paramType) {
        this.paramType = paramType == null ? null : paramType.trim();
    }

    public String getParamValue() {
        return paramValue;
    }

    public void setParamValue(String paramValue) {
        this.paramValue = paramValue == null ? null : paramValue.trim();
    }

    public String getParamFormat() {
        return paramFormat;
    }

    public void setParamFormat(String paramFormat) {
        this.paramFormat = paramFormat == null ? null : paramFormat.trim();
    }

    public String getParamNote() {
        return paramNote;
    }

    public void setParamNote(String paramNote) {
        this.paramNote = paramNote == null ? null : paramNote.trim();
    }


    public Object getParamObject() {
        if (StringUtils.isNull(this.paramValue)) return null;
        try {
            switch (this.paramType) {
                case "int":
                    return Integer.parseInt(this.paramValue);
                case "double":
                    return Double.parseDouble(this.paramValue);
                case "boolean":
                    return Boolean.parseBoolean(this.paramValue);
                case "long":
                    return Long.parseLong(this.paramValue);
                case "float":
                    return Float.parseFloat(this.paramValue);
                case "string":
                    return this.paramValue; // 直接返回字符串
            }
        } catch (NumberFormatException e) {
            throw new RuntimeException("Failed to convert value: " + this.paramValue + " to type: " + this.paramType, e);
        }
        return null;
    }

}
