package cn.hanghui.outapi.platform.tenant.entity.dto.auth;

import cn.hanghui.outapi.platform.common.utils.Preconditions;
import cn.hanghui.outapi.platform.tenant.entity.enums.InterfaceTypeEnum;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

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

/**
 * @author shisl
 * @package cn.hanghui.outapi.platform.tenant.entity.dto.auth
 * @class OpenInterfaceAuthVo
 * @date 2024/1/17 下午1:39
 * @description
 */
@Data
public class OpenInterfaceAuthVo implements Serializable {

    private Long id;

    @ApiModelProperty(value = "购买方公司id")
    private Long purchaserId;

    @ApiModelProperty(value = "购买方公司名称")
    private String purchaserName;

    @ApiModelProperty(value = "是否开启返回详细信息 0关闭 1开启 默认1开启")
    private Boolean resultInfoSwitch;

    @ApiModelProperty(value = "InterfaceTypeEnum 接口类型 0:风险评分 [1,2,3]")
    private Integer interfaceType;

    @ApiModelProperty(value = "InterfaceTypeEnum 接口类型 0:风险评分 [1,2,3]")
    private String interfaceTypeDesc;

    @ApiModelProperty(value = "总调用次数 null不限制")
    private Integer limitTimes;

    @ApiModelProperty(value = "单位时间调用频次 0或null不限制")
    private Integer limitFrequency;

    @ApiModelProperty(value = "调用频次单位时间 单位秒 0或null不限制")
    private Integer limitFrequencyTime;

    @ApiModelProperty(value = "appId 32位 9805f4fb52a90a6941935fc3290673f4")
    private String appId;

    @ApiModelProperty(value = "权限校验的appKey")
    private String appKey;

    @ApiModelProperty(value = "权限校验的appSecret")
    private String appSecret;

    @ApiModelProperty(value = "权限校验的privateKey 16位随机数 包含字母和数据")
    private String privateKey;

    @ApiModelProperty(value = "已调用次数")
    private Integer hadReqTimes;

    @ApiModelProperty(value = "最后一次请求时间")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date latestReqTime;

    @ApiModelProperty(value = "是否启用0:未启用 1:启用")
    private Boolean status;

    @ApiModelProperty(value = "描述")
    private String description;

    @ApiModelProperty(value = "额外扩展参数 巨龙:（{\"searchSwitchProvince\":false,\"xpSwitch\":false,\"dzSwitch\":false}） ")
    private String extendParams;

    @ApiModelProperty(value = "创建时间")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;

    public static List<Integer> convertStr2InterfaceTypes(String interfaceTypeStr) {
        List<Integer> list = JSONObject.parseArray(interfaceTypeStr, Integer.class);
        return list;
    }

    public static List<String> convert2InterfaceTypeDesc(List<Integer> codes) {
        List<String> desc = new ArrayList<>();
        if (Preconditions.isBlank(codes)) {
            return desc;
        }
        codes.stream().forEach(item -> {
            InterfaceTypeEnum type = InterfaceTypeEnum.findByCode(item);
            if (Preconditions.isNotBlank(type)) {
                desc.add(type.getDesc());
            }
        });
        return desc;
    }

}
