/*
 * 文 件 名:  CommonCall
 * 版    权:  华设设计集团股份有限公司
 * 描    述:  <描述>
 * 修 改 人:  lvwenbin
 * 修改时间:  2025/9/24
 * 跟踪单号:  <跟踪单号>
 * 修改单号:  <修改单号>
 * 修改内容:  <修改内容>
 */
package com.ruoyi.ems.model;

import lombok.Getter;

import java.util.List;

/**
 * CallData
 * <功能详细描述>
 *
 * @author lvwenbin
 * @version [版本号, 2025/9/24]
 * @see [相关类/方法]
 * @since [产品/模块版本]
 */
public class CallData<T> {
    @Getter
    private final String callPayload;

    @Getter
    private final String resPayload;

    @Getter
    private final Integer callStatus;

    @Getter
    private final T data;

    @Getter
    private final List<T> list;

    // 私有构造方法，只能通过Builder创建对象
    private CallData(Builder<T> builder) {
        this.callPayload = builder.callPayload.toString();
        this.resPayload = builder.resPayload.toString();
        this.callStatus = builder.callStatus;
        this.data = builder.data;
        this.list = builder.list;
    }

    // Builder类
    public static class Builder<T> {
        private StringBuilder callPayload = new StringBuilder();

        private StringBuilder resPayload = new StringBuilder();

        private Integer callStatus;

        private T data;

        private List<T> list;

        public Builder() {
        }

        /**
         * 链式添加callPayload键值对
         */
        public Builder<T> addCallParam(String key, Object value) {
            this.callPayload.append(key).append(": ").append(value).append(System.lineSeparator());
            return this;
        }

        /**
         * 设置resPayload
         */
        public Builder<T> setResPayload(String resPayload) {
            this.resPayload = new StringBuilder(resPayload);
            return this;
        }

        public Builder<T> appendResPayload(String resPayload) {
            this.resPayload.append(resPayload);
            return this;
        }

        /**
         * 设置resPayload
         */
        public Builder<T> setCallStatus(Integer callStatus) {
            this.callStatus = callStatus;
            return this;
        }

        /**
         * 设置data
         */
        public Builder<T> setData(T data) {
            this.data = data;
            return this;
        }

        /**
         * 设置data
         */
        public Builder<T> setList(List<T> list) {
            this.list = list;
            return this;
        }

        /**
         * 构建CallData对象
         */
        public CallData<T> build() {
            return new CallData<>(this);
        }
    }

    // 用于获取Builder实例的静态方法
    public static <T> Builder<T> builder() {
        return new Builder<>();
    }
}