package com.tofly.feesapi.bmgl.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.tofly.feesapi.bmgl.entity.BmCbb;
import com.tofly.feesapi.bmgl.entity.BmCbpq;
import com.tofly.feesapi.bmgl.entity.dto.CbbConfigDto;
import com.tofly.feesapi.bmgl.service.CbbConfigService;
import com.tofly.feesapi.common.core.ResultRespone;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("cbbConfig")
@Api(tags = "用户-抄表本(册)配置")
public class CbbConfigController {

    @Autowired
    private CbbConfigService cbbConfigService;

    @ApiOperationSupport(order = 2)
    @GetMapping("/{userId}")
    @ApiOperation(value = "通过用户id查询配置的抄表本")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", required = true, dataType = "Long")
    })
    public ResultRespone<List<BmCbb>> getConfigByUserId(@PathVariable("userId") Long userId) {
        return ResultRespone.success(cbbConfigService.getByCbbByUserId(userId));
    }

    @ApiOperationSupport(order = 3)
    @GetMapping("getCbPqInfo")
    @ApiOperation(value = "获取抄表片区（权限）")
    public ResultRespone<List<BmCbpq>> getCbPqInfo() {
        return ResultRespone.success(cbbConfigService.getCbPqInfo());
    }

    @ApiOperationSupport(order = 4)
    @GetMapping("getCbbInfo")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "sscbpq", value = "所属抄表片区", required = false, dataType = "String")
    })
    @ApiOperation(value = "根据抄表片区获取抄表本（权限）")
    public ResultRespone<List<BmCbb>> getCbbInfo(String sscbpq) {
        return ResultRespone.success(cbbConfigService.getCbbInfo(sscbpq));
    }


    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "用户-抄表本(册)权限配置")
    @PostMapping("/save")
    public ResultRespone<Boolean> saveConfig(@RequestBody CbbConfigDto userCbbConfig) {
        return ResultRespone.success(cbbConfigService.saveConfig(userCbbConfig));
    }

}
