package com.cool.store.controller.webb;

import com.cool.store.common.InsertGroup;
import com.cool.store.common.UpdateGroup;
import com.cool.store.request.fees.PayeeBankConfigAddRequest;
import com.cool.store.request.fees.PayeeBankConfigPageRequest;
import com.cool.store.response.ResponseResult;
import com.cool.store.service.fees.PayeeBankConfigService;
import com.cool.store.vo.fees.PayeeBankConfigVO;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

/**
 * 线下收款银行配置Controller
 */
@Api(tags = "线下收款银行配置")
@RestController
@RequestMapping("/pc/fees/bankConfig")
@RequiredArgsConstructor
@Validated
public class PayeeBankConfigController {

    private final PayeeBankConfigService payeeBankConfigService;

    @ApiOperation("新增")
    @PostMapping("/add")
    public ResponseResult<Boolean> add(@RequestBody @Validated({InsertGroup.class}) PayeeBankConfigAddRequest request) {
        return ResponseResult.success(payeeBankConfigService.add(request));
    }

    @ApiOperation("编辑")
    @PostMapping("/update")
    public ResponseResult<Boolean> update(@RequestBody @Validated({UpdateGroup.class}) PayeeBankConfigAddRequest request) {
        return ResponseResult.success(payeeBankConfigService.update(request));
    }

    @ApiOperation("分页查询")
    @PostMapping("/page")
    public ResponseResult<PageInfo<PayeeBankConfigVO>> page(@RequestBody PayeeBankConfigPageRequest request) {
        return ResponseResult.success(payeeBankConfigService.page(request));
    }

    @ApiOperation("根据门店查询线下收款银行")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "shopId", value = "门店id", required = true),
            @ApiImplicitParam(name = "payType", value = "付款方式 1线下支付 2平安钱包支付", required = true),
    })
    @GetMapping("/getBankConfig")
    public ResponseResult<PayeeBankConfigVO> getBankConfig(@NotNull(message = "门店id不能为空") Long shopId,
                                                           Integer payType) {
        return ResponseResult.success(payeeBankConfigService.getByShopId(shopId, payType));
    }
}


