package com.njcn.device.pq.controller;

import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.enums.common.LogEnum;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.device.pq.pojo.param.FlowMealParam;
import com.njcn.device.pq.pojo.param.FlowStrategyParam;
import com.njcn.device.pq.pojo.vo.FlowStrategyVO;
import com.njcn.device.pq.pojo.vo.RateOfFlowVO;
import com.njcn.device.pq.pojo.vo.ShowFlowStrategyVO;
import com.njcn.device.pq.service.FlowMealService;
import com.njcn.device.pq.service.FlowStrategyService;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @version 1.0.0
 * @author: chenchao
 * @date: 2022/05/11 10:08
 */
@Validated
@Slf4j
@RestController
@RequestMapping("/rateOfFlow")
@Api(tags = "流量管理")
@AllArgsConstructor
public class RateOfFlowController extends BaseController {

    private final FlowMealService flowMealService;

    private final FlowStrategyService flowStrategyService;

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getRateOfFlowData")
    @ApiOperation("流量套餐管理")
    public HttpResult<List<RateOfFlowVO>> getRateOfFlowData(){
        String methodDescribe = getMethodDescribe("getRateOfFlowData");
        List<RateOfFlowVO> list = flowMealService.getRateOfFlowData();
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/addRateOfFlowData")
    @ApiOperation("新增流量套餐")
    @ApiImplicitParam(name = "flowMealParam", value = "流量套餐信息", required = true)
    public HttpResult addRateOfFlowData(@RequestBody @Validated FlowMealParam flowMealParam){
        String methodDescribe = getMethodDescribe("addRateOfFlowData");
        boolean res = flowMealService.addRateOfFlowData(flowMealParam);
        if (res) {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
        } else {
            throw new BusinessException(CommonResponseEnum.FAIL);
        }
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/updateRateOfFlowData")
    @ApiOperation("修改流量套餐")
    @ApiImplicitParam(name = "flowMealUpdateParam", value = "套餐更改信息", required = true)
    public HttpResult updateRateOfFlowData(@RequestBody @Validated FlowMealParam.FlowMealUpdateParam flowMealUpdateParam){
        String methodDescribe = getMethodDescribe("updateRateOfFlowData");
        boolean res = flowMealService.updateRateOfFlowData(flowMealUpdateParam);
        if (res) {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
        } else {
            throw new BusinessException(CommonResponseEnum.FAIL);
        }
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/deleteRateOfFlowData")
    @ApiOperation("删除流量套餐")
    @ApiImplicitParam(name = "id", value = "套餐更改id", required = true)
    public HttpResult deleteRateOfFlowData(@NotNull(message = "id不可为空") @RequestParam("id")String id){
        String methodDescribe = getMethodDescribe("deleteRateOfFlowData");
        boolean res = flowMealService.deleteRateOfFlowData(id);
        if (res) {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
        } else {
            throw new BusinessException(CommonResponseEnum.FAIL);
        }
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getRateOfFlowStrategy")
    @ApiOperation("流量策略管理")
    public HttpResult<List<FlowStrategyVO>> getRateOfFlowStrategy(){
        String methodDescribe = getMethodDescribe("getRateOfFlowStrategy");
        List<FlowStrategyVO> list = flowStrategyService.getRateOfFlowStrategy();
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/addRateOfFlowStrategy")
    @ApiOperation("新增流量策略")
    @ApiImplicitParam(name = "flowStrategyParam", value = "流量套餐信息", required = true)
    public HttpResult addRateOfFlowStrategy(@RequestBody @Validated FlowStrategyParam flowStrategyParam){
        String methodDescribe = getMethodDescribe("addRateOfFlowStrategy");
        boolean res = flowStrategyService.addRateOfFlowStrategy(flowStrategyParam);
        if (res) {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
        } else {
            throw new BusinessException(CommonResponseEnum.FAIL);
        }
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getFlowStrategyById")
    @ApiOperation("流量策略数据回显")
    @ApiImplicitParam(name = "id", value = "流量策略id", required = true)
    public HttpResult<ShowFlowStrategyVO> getFlowStrategyById(@RequestParam("id") String id){
        String methodDescribe = getMethodDescribe("getFlowStrategyById");
        ShowFlowStrategyVO result = flowStrategyService.getFlowStrategyById(id);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/updateRateOfFlowStrategy")
    @ApiOperation("修改流量策略")
    @ApiImplicitParam(name = "flowStrategyUpdateParam", value = "流量策略更改信息", required = true)
    public HttpResult updateRateOfFlowStrategy(@RequestBody @Validated FlowStrategyParam.FlowStrategyUpdateParam flowStrategyUpdateParam){
        String methodDescribe = getMethodDescribe("updateRateOfFlowStrategy");
        boolean res = flowStrategyService.updateRateOfFlowStrategy(flowStrategyUpdateParam);
        if (res) {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
        } else {
            throw new BusinessException(CommonResponseEnum.FAIL);
        }
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/deleteRateOfFlowStrategy")
    @ApiOperation("删除流量策略")
    @ApiImplicitParam(name = "id", value = "策略更改id", required = true)
    public HttpResult deleteRateOfFlowStrategy(@NotNull(message = "id不可为空") @RequestParam("id")String id){
        String methodDescribe = getMethodDescribe("deleteRateOfFlowStrategy");
        boolean res = flowStrategyService.deleteRateOfFlowStrategy(id);
        if (res) {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
        } else {
            throw new BusinessException(CommonResponseEnum.FAIL);
        }
    }


}
