package com.tmerclub.cloud.platform.controller;

import com.tmerclub.cloud.common.database.dto.PageDTO;
import com.tmerclub.cloud.common.database.vo.PageVO;
import com.tmerclub.cloud.common.response.ServerResponseEntity;
import com.tmerclub.cloud.platform.dto.PublicBankDTO;
import com.tmerclub.cloud.platform.service.PublicBankService;
import com.tmerclub.cloud.platform.vo.PublicBankVO;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author gaozijie
 * @date 2023-03-21
 */
@RestController
@RequestMapping("/ua/public_bank")
public class PublicBankController {

    @Autowired
    private PublicBankService publicBankService;

    @GetMapping("/list")
    @Operation(summary = "获取对公户银行列表", description = "获取对公户银行列表")
    public ServerResponseEntity<List<PublicBankVO>> listPublicBank(PublicBankDTO publicBankDTO) {
        List<PublicBankVO> publicBankVOList = publicBankService.listPublicBank(publicBankDTO);
        return ServerResponseEntity.success(publicBankVOList);
    }

    @GetMapping("/page")
    @Operation(summary = "分页获取对公户银行列表", description = "分页获取对公户银行列表")
    public ServerResponseEntity<PageVO<PublicBankVO>> pagePublicBank(PageDTO pageDTO,
                                                                     PublicBankDTO publicBankDTO) {
        PageVO<PublicBankVO> pageVO = publicBankService.pagePublicBank(pageDTO, publicBankDTO);
        return ServerResponseEntity.success(pageVO);
    }

    @PostMapping("/save")
    @Operation(summary = "保存", description = "保存")
    public ServerResponseEntity<Void> save(@RequestBody PublicBankDTO publicBankDTO) {
        publicBankService.save(publicBankDTO);
        return ServerResponseEntity.success();
    }

    @PutMapping("/update")
    @Operation(summary = "更新", description = "更新")
    public ServerResponseEntity<Void> update(@RequestBody PublicBankDTO publicBankDTO) {
        publicBankService.update(publicBankDTO);
        return ServerResponseEntity.success();
    }

    @DeleteMapping("/deleteByIds")
    @Operation(summary = "批量删除", description = "批量删除")
    public ServerResponseEntity<Void> deleteByIds(List<Long> bankIds) {
        publicBankService.deleteByIds(bankIds);
        return ServerResponseEntity.success();
    }
}
