package com.yn.bftl.thirdparty.modules.chinaums.controller.member;

import com.alibaba.fastjson.JSONObject;
import com.yn.bftl.thirdparty.modules.chinaums.dto.ChinaumsPostDTO;
import com.yn.bftl.thirdparty.modules.chinaums.service.ToolService;
import com.yn.bftl.thirdparty.modules.chinaums.vo.BankLineNumberVO;
import com.yn.bftl.thirdparty.modules.chinaums.vo.ChinaumsImageVO;
import io.swagger.annotations.*;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.time.LocalDate;

/**
 * @author huabiao
 * @create 2022/12/6  17:05
 **/
@Validated
@Api(value = "ToolMemberController", tags = "用户端-银联工具")
@RestController
@RequestMapping("/member/chinaums/tool")
public class ToolMemberController {

    @Resource
    private ToolService toolService;

    @ApiOperation(value = "图片上传")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "front：身份证含照片的一面 back：身份证带国徽的一面 business_license：营业执照")
    })
    @PostMapping("/upload")
    public ChinaumsImageVO upload(@RequestPart @RequestParam("file") @ApiParam(value = "文件", required = true) MultipartFile file,
                                  String type) {
        return toolService.uploadImage(file, type);
    }

    @ApiOperation(value = "银行-列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "keyword", value = "银行名称", dataType = "String", dataTypeClass = String.class),
    })
    @RequestMapping(value = "/bank_list", method = RequestMethod.GET)
    public Page<BankLineNumberVO> getBankList(String keyword, Pageable pageable) {
        return toolService.getBankList(keyword, pageable);
    }

    @ApiOperation(value = "打款金额验证")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "amount", value = "打款金额", dataType = "BigDecimal", dataTypeClass = BigDecimal.class, required = true),
    })
    @RequestMapping(value = "/amount_validate", method = RequestMethod.GET)
    public Boolean amountValidate(@NotNull BigDecimal amount) {
        return toolService.amountValidate(amount);
    }

    @ApiOperation(value = "发送验证码")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "mobile", value = "手机号", dataType = "String", dataTypeClass = String.class, required = true),
    })
    @RequestMapping(value = "/sms_codes", method = RequestMethod.GET)
    public void smsCodes(@NotBlank String mobile) {
        toolService.smsCodes(mobile);
    }

    @ApiOperation("账单下载")
    @GetMapping("/trade_bills")
    public String tradeBills(@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate billDate) {
        return toolService.tradeBills(billDate);
    }

    @ApiOperation(value = "重置交易密码-发送验证码")
    @RequestMapping(value = "/reset_password/sms_codes", method = RequestMethod.GET)
    public void smsCodesForResetPassword() {
        toolService.smsCodesForResetPassword();
    }

    @ApiOperation(value = "银联接口-调用")
    @RequestMapping(value = "/post", method = RequestMethod.POST)
    public JSONObject postTool(@Validated @RequestBody ChinaumsPostDTO chinaumsPostDTO) {
        return toolService.postTool(chinaumsPostDTO);
    }
}
