package com.ytpm.controller;

import com.ytpm.app.model.YtDyzUser;
import com.ytpm.general.Result;
import com.ytpm.risk.view.RiskTemplateView;
import com.ytpm.service.RiskService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/public")
public class PublicApiController {

    @Autowired
    private RiskService riskService;

    /**
     * 根据appId查询应用配置模版
     */
    @ApiOperation("返回指定应用关联的风控配置")
    @GetMapping("/getRiskCondition")
    public Result<RiskTemplateView> getRiskCondition(@RequestParam("app_id")String appId){
        return riskService.getAppConfig(appId);
    }

    /**
     * 登录检查默认风控配置
     */
    @ApiOperation("登录检查默认风控配置")
    @PostMapping("/checkRisk")
    public Result<?> checkRisk(@RequestBody YtDyzUser dyzUser){
        return riskService.checkRisk(dyzUser);
    }

    /**
     * 根据风控编码获取风控配置
     */
    @ApiOperation("根据风控编码获取风控配置")
    @GetMapping("/getRiskByCode")
    public Result<RiskTemplateView> getRiskByCode(@RequestParam("code")String code){
        return riskService.getRiskByCode(code);
    }
    /**
     * 根据应用获取风控配置
     */
    @ApiOperation("根据应用ID获取风控配置")
    @GetMapping("/getRiskTemplate")
    public List<RiskTemplateView> getRiskTemplate(@RequestParam("appId")String appId){
        return riskService.getRiskTemplate(appId);
    }

    /**
     * 校验广告的默认风控配置
     */
    @ApiOperation("校验广告的默认风控配置")
    @PostMapping("/checkAdRisk")
    public Result<?> checkAdRisk(@RequestBody YtDyzUser dyzUser){
       return riskService.checkAdRisk(dyzUser);
    }

    /**
     * 校验广告的默认风控配置 766
     */
    @ApiOperation("校验广告的默认风控配置")
    @PostMapping("/checkAdRisk/766")
    public Result<?> checkAdRisk766(@RequestBody YtDyzUser dyzUser){
       return riskService.checkAdRisk766(dyzUser);
    }

    /**
     * 批量审核用户
     */
    @ApiOperation("批量审核用户")
    @PostMapping("/batchAudit")
    public void batchAudit(@RequestParam("userList") List<YtDyzUser> userList){
        riskService.batchAudit(userList);
    }

    @ApiOperation("增加解禁记录")
    @GetMapping("/addDeblockingRecord")
    public void addDeblockingRecord(@RequestParam(name = "userId")String userId){
        riskService.addDeblockingRecord(userId);
    }

    @ApiOperation("校验注册风控配置")
    @PostMapping("/checkRegRisk")
    public Result<?> checkRegRisk(@RequestBody YtDyzUser dyzUser){
        return riskService.checkRegRisk(dyzUser);
    }

    @ApiOperation("校验登录风控配置")
    @PostMapping("/checkLoginRisk")
    public Result<?> checkLoginRisk(@RequestBody YtDyzUser dyzUser){
        return riskService.checkLoginRisk(dyzUser);
    }
}
