package com.tofly.watermeter.custom.controller.meterBusiness;

import com.tofly.common.core.entity.ResultRespone;
import com.tofly.watermeter.custom.service.meterBusiness.ConfigManageService;
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.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

@RestController
@AllArgsConstructor
@RequestMapping("/configManage")
@Api(tags = "表务管理-配置管理改动接口")
public class ConfigManageController {

    private final ConfigManageService configManageService;

    @GetMapping("/query")
    @ApiOperation("配置管理查询及导出")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "export", value = "0 不导出 1导出", required = true, dataType = "long"),
            @ApiImplicitParam(name = "choose", value = "0 厂家 1 口径 2 类型", required = true, dataType = "string")
    })
    public ResultRespone query(HttpServletResponse response, Long export, String choose) {
        if ("0".equals(choose)) {
            return ResultRespone.success(configManageService.vendorConfig(response, export));
        } else if ("1".equals(choose)) {
            return ResultRespone.success(configManageService.calConfig(response, export));
        } else {
            return ResultRespone.success(configManageService.typeConfig(response, export));
        }
    }

    @PostMapping("synVendor")
    @ApiOperation("厂家编码同步")
    public ResultRespone synVendor() {
        return ResultRespone.success(configManageService.synVendor());
    }

}
