package top.r3944realms.lib39.core.command.model;

import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;

/**
 * The type Parameter.
 */
public record Parameter(String name, boolean required) {

    /**
     * 獲取參數類型標識
     *
     * @return the type indicator
     */
    @Contract(pure = true)
    public @NotNull String getTypeIndicator() {
        return required ? "required" : "optional";
    }

    @Override
    public String toString() {
        return String.format("Parameter{name='%s', required=%s}", name, required);
    }

    /**
     * The type Builder.
     */
    public static class Builder {
        private final List<Parameter> parameters = new ArrayList<>();

        /**
         * Required builder.
         *
         * @param name the name
         * @return the builder
         */
        public Builder required(String name) {
            parameters.add(new Parameter(name, true));
            return this;
        }

        /**
         * Optional builder.
         *
         * @param name the name
         * @return the builder
         */
        public Builder optional(String name) {
            parameters.add(new Parameter(name, false));
            return this;
        }


        /**
         * Build parameter [ ].
         *
         * @return the parameter [ ]
         */
        public Parameter[] build() {
            return parameters.toArray(new Parameter[0]);
        }

        /**
         * Builder parameter . builder.
         *
         * @return the parameter . builder
         */
// 链式调用的便利方法
        @Contract(" -> new")
        public static @NotNull Parameter.Builder builder() {
            return new Builder();
        }
    }
}
