package cn.pluss.platform.controller;


import cn.pluss.platform.api.Result;
import cn.pluss.platform.api.ResultGenerator;
import cn.pluss.platform.base.BaseModelController;
import cn.pluss.platform.cashAccount.CashAccountService;
import cn.pluss.platform.entity.CashAccount;
import cn.pluss.platform.exception.MsgException;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author bzg
 * @since 2021-07-23
 */
@RestController
@RequestMapping("/cashAccount")
public class CashAccountController extends BaseModelController<CashAccountService, CashAccount> {

    @ApiOperation(tags = {"提现账户-保存"}, value = "保存提现账号", notes = "保存提现账号", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "cashAccount", value = "保存的cashAccount实例", paramType = "body", dataType = "CashAccount", required = true) })
    @Override
    public Result<String> save(@Valid @RequestBody CashAccount entity) {
        try {
            baseService.apiSave(entity);
            return ResultGenerator.genSuccessResult("保存成功", null);
        }catch (RuntimeException e){
            MsgException.throwException(e.getMessage());
        }

        return null;
    }

    @GetMapping(value = "get/{userId}")
    @ApiOperation(tags = {"获取提现-查询"}, value = "查询提现账号", notes = "查询提现账号", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "cashAccount", value = "查询cashAccount实例", paramType = "params", required = true) })
    public Result<CashAccount> get(@PathVariable("userId") Integer userId) {
        return super.get(new CashAccount().setUserId(userId));
    }
}
