package com.wzj.soopin.member.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wzj.soopin.member.convert.MemberBankConvert;
import com.wzj.soopin.member.domain.bo.MemberBankBO;
import com.wzj.soopin.member.domain.po.MemberBank;
import com.wzj.soopin.member.domain.vo.MemberBankVO;
import com.wzj.soopin.member.service.IMemberBankService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.springframework.web.bind.annotation.*;

/**
 * 用户银行卡
 */
@Tag(name = "用户银行卡")
@RestController
@RequestMapping("/ums/bank")
@RequiredArgsConstructor
public class MemberBankController {

    private final IMemberBankService service;
    private final MemberBankConvert convert;

    @Operation(summary = "查询银行卡列表")
    @PostMapping("/list")
    public R<IPage<MemberBankVO>> list(@RequestBody MemberBankBO bo, @RequestBody Page page) {
        Page<MemberBank> pages = service.page(page, bo.toWrapper());
        return R.ok(convert.toVO(pages));
    }

    @Operation(summary = "新增银行卡")
    @Log(title = "新增银行卡", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public R add(@RequestBody MemberBankBO bo) {
        return R.ok(service.save(convert.toPo(bo)));
    }

    @Operation(summary = "获取银行卡详情")
    @GetMapping(value = "/{id}")
    public R<MemberBankVO> getInfo(@PathVariable("id") Long id) {
        return R.ok(convert.toVO(service.getById(id)));
    }

    @Operation(summary = "修改银行卡")
    @Log(title = "修改银行卡", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    public R update(@RequestBody MemberBankBO bo) {
        service.save(convert.toPo(bo));
        return R.ok();
    }


    @Operation(summary = "删除银行卡")
    @Log(title = "删除银行卡", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public R<Object> remove(@PathVariable Long id) {
        return R.ok(service.removeById(id));
    }
}
