package com.chinaweal.aiccs.aiccs.security.entity.vo;

import com.alibaba.fastjson.annotation.JSONField;
import com.chinaweal.aiccs.aiccs.security.enums.ErrorCode;
import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 批量报销板块的ResultVO
 *
 * @author lroyia
 * @since 2026/1/12 15:48
 **/
@Data
@Accessors(chain = true)
public class SecurityResultVO implements Serializable {

    private static final long serialVersionUID = 1L;

    public static final String SUCCESS = "SUCCESS";
    public static final String FAILURE = "FAILURE";

    @JSONField(name = "ack_code")
    private String ackCode;

    @JSONField(name = "errors")
    private List<ErrorInfoVO> errors;

    /**
     * 创建请求成功信息
     *
     * @return 成功
     */
    public static SecurityResultVO success() {
        SecurityResultVO resultVO = new SecurityResultVO();
        resultVO.setAckCode(SUCCESS);
        resultVO.errors = new ArrayList<>(0);
        return resultVO;
    }

    /**
     * 创建失败返回信息
     *
     * @return 成功
     */
    public static SecurityResultVO error(ErrorCode... codes) {
        SecurityResultVO resultVO = new SecurityResultVO();
        resultVO.setAckCode(FAILURE);
        resultVO.errors = new ArrayList<>(codes == null ? 0 : codes.length);
        if (codes != null) {
            for (ErrorCode code : codes) {
                resultVO.errors.add(new ErrorInfoVO().setErrorCode(code.getCode()).setName(code.getName()).setMessage(code.getMessage()));
            }
        }
        return resultVO;
    }
}
