/*
 * Copyright 2017-2025 noear.org and authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.noear.solon.ai.util;

import org.noear.solon.core.Constants;
import org.noear.solon.core.util.Assert;
import org.noear.solon.expression.snel.SnEL;

import java.lang.reflect.Type;
import java.util.Map;

/**
 * 函数工具参数描述
 *
 * @author noear
 * @since 3.1
 */
public class ParamDesc {
    private final String name;
    private final Type type;
    private final boolean required;
    private final String defaultValue;
    private final String format;
    private String description;

    public ParamDesc(String name, Type type, boolean required, String description, String defaultValue, String format) {
        this.name = name;
        this.type = type;
        this.required = required;
        this.description = (description == null ? "" : description);
        this.defaultValue = Constants.PARM_UNDEFINED_VALUE.equals(defaultValue) ? null : defaultValue;
        this.format = format;
    }

    public ParamDesc binding(Map<String, Object> binding) {
        if (Assert.isNotEmpty(binding)) {
            this.description = SnEL.evalTmpl(description, binding);
        }

        return this;
    }

    /**
     * 参数名字
     */
    public String name() {
        return name;
    }

    /**
     * 参数类型
     */
    public Type type() {
        return type;
    }

    /**
     * 参数描述
     */
    public String description() {
        return description;
    }

    /**
     * 默认值
     */
    public String defaultValue() {
        return defaultValue;
    }

    /**
     * 格式化
     */
    public String format() {
        return format;
    }

    /**
     * 是否必须
     */
    public boolean required() {
        return required;
    }

    @Override
    public String toString() {
        return "ParamDesc{" +
                "name='" + name + '\'' +
                ", description='" + description + '\'' +
                ", defaultValue='" + defaultValue + '\'' +
                ", format='" + format + '\'' +
                ", required=" + required +
                ", type=" + type +
                '}';
    }
}