package com.malk.server.dingtalk;

import com.malk.server.common.McException;
import com.malk.server.common.VenR;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;
import java.util.Map;

/**
 * 返回值配置参考McR
 */
@Data
@NoArgsConstructor
public class DDR<T> extends VenR {

    // 请求状态
    private boolean success;

    private String errcode;

    private String errmsg;

    private T result;

    /**
     * token
     */
    private String accessToken;
    private int expiresIn;

    /**
     * ticket
     */
    private String ticket;

    /**
     * 审批实例ID
     */
    private String processInstanceId;

    /**
     * 审批实例详情
     */
    private Map processInstance;

    /**
     * 回调失败事件
     */
    private List<Map> failedList;

    private boolean hasMore;

    private String corpid;

    /**
     * 发送工作通知
     */
    private String task_id; // 可调用获取工作通知消息的发送结果查询结果

    /**
     * 考勤打卡数据
     */
    private List<Map> recordresult;

    // 成功状态标记
    private final static String SUC_CODE = "0";

    // 创建用户邀请成功提示
    private final static String USER_CREATE = "40103";

    /**
     * 断言错误信息
     */
    @Override
    public void assertSuccess() {
        McException.assertException(!errcode.equals(SUC_CODE) && !errcode.equals(USER_CREATE), errcode, errmsg, "dingtalk");
    }

    /**
     * 通用post请求
     */
    public static DDR doPost(String url, Map header, Map param, Map body) {
        return (DDR) DDR.doPost(url, header, param, body, VenR.RC_DD);
    }

    /**
     * 通用get请求
     */
    public static DDR doGet(String url, Map header, Map param) {
        return (DDR) DDR.doGet(url, header, param, VenR.RC_DD);
    }
}
