package com.ruoyi.controller;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.annotations.UserLoginToken;
import com.ruoyi.code.PublicCommon;
import com.ruoyi.common.core.domain.BaseEntity;
import com.ruoyi.common.page.PageResult;
import com.ruoyi.controller.req.BankCardAddReq;
import com.ruoyi.controller.req.BankCardEditReq;
import com.ruoyi.controller.req.BankCardPageReq;
import com.ruoyi.controller.resp.BankCardDetailResp;
import com.ruoyi.controller.resp.BankCardPageResp;
import com.ruoyi.frequency.bankcard.entity.BankCard;
import com.ruoyi.frequency.bankcard.service.BankCardService;
import com.ruoyi.response.ResponseData;
import com.ruoyi.vo.BodyIdReq;
import com.ruoyi.vo.RyController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/api/bankCard")
@Api(tags = "银行卡")
public class ApiBankCardController extends RyController {


    @Autowired
    private BankCardService bankCardService;

    @PostMapping("/bankCardPage")
    @ApiOperation(value = "银行卡列表", notes = "银行卡列表")
    @UserLoginToken
    public ResponseData<PageResult<Page<BankCardPageResp>>> bankCardPage(@RequestBody BankCardPageReq req) {
        return bankCardService.bankCardPage(req,getUserVo());
    }

    @PostMapping("/bankCardList")
    @ApiOperation(value = "银行卡列表(不分页)", notes = "银行卡列表")
    @UserLoginToken
    public ResponseData<List<BankCard>> bankCardList() {
        List<BankCard> list = bankCardService.list(new LambdaUpdateWrapper<BankCard>()
                .eq(BankCard::getDelFlag, PublicCommon.启用)
                .orderByDesc(BaseEntity::getCreateTime)
        );
        return ResponseData.success(list);
    }

    @PostMapping("/bankCardAdd")
    @ApiOperation(value = "银行卡新增", notes = "银行卡新增")
    @UserLoginToken
    public ResponseData bankCardAdd(@RequestBody BankCardAddReq req) {
        return bankCardService.bankCardAdd(req,getUserVo());
    }

    @PostMapping("/bankCardEdit")
    @ApiOperation(value = "银行卡编辑", notes = "银行卡编辑")
    @UserLoginToken
    public ResponseData bankCardEdit(@RequestBody BankCardEditReq req) {
        return bankCardService.bankCardEdit(req,getUserVo());
    }

    @PostMapping("/bankCardDetail")
    @ApiOperation(value = "银行卡详情", notes = "银行卡详情")
    @UserLoginToken
    public ResponseData<BankCardDetailResp> bankCardDetail(@RequestBody BodyIdReq req) {
        return bankCardService.bankCardDetail(req.getId(),getUserVo());
    }

    @PostMapping("/bankCardDel")
    @ApiOperation(value = "银行卡删除", notes = "银行卡删除")
    @UserLoginToken
    public ResponseData bankCardDel(@RequestBody BodyIdReq req) {
        return bankCardService.bankCardDel(req.getId(),getUserVo());
    }
}
