package com.sqx.modules.datacentre.controller;

import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.sqx.common.utils.Result;
import com.sqx.modules.datacentre.entity.RiderBankCardInfo;
import com.sqx.modules.datacentre.service.RiderBankCardInfoService;
import com.sqx.modules.shop.entity.ShopBankCardInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@Api(tags={"骑手银行卡信息"})
@RestController
@RequestMapping("/rider/bank")
public class RiderBankCardInfoController {

    @Autowired
    private RiderBankCardInfoService riderBankCardInfoService;

    @ApiOperation("新增骑手银行卡信息")
    @PostMapping("/save")
    public Result saveCardInfo(@Valid @RequestBody RiderBankCardInfo riderBankCardInfo) {
        return riderBankCardInfoService.saveCardInfo(riderBankCardInfo);
    }

    @ApiOperation("查询单个骑手银行卡信息")
    @GetMapping("/getUserId")
    public Result getUserIdCardInfo(Long userId) {
        return riderBankCardInfoService.getUserIdCardInfo(userId);
    }

    @ApiOperation("编辑骑手银行卡信息")
    @PostMapping("/update")
    public Result updateCardInfo(@Valid @RequestBody RiderBankCardInfo riderBankCardInfo) {
        Long id = riderBankCardInfo.getId();
        if (ObjectUtils.isEmpty(id)) {
            return riderBankCardInfoService.saveCardInfo(riderBankCardInfo);
        }
        riderBankCardInfoService.updateById(riderBankCardInfo);
        return Result.success();
    }

    @ApiOperation("删除骑手银行卡信息")
    @GetMapping("/delete")
    public Result deleteIdCardInfo(Long id) {
        riderBankCardInfoService.removeById(id);

        return Result.success();
    }



}
