package com.reyun.saas.web.controller.user;

import com.reyun.saas.common.framework.ApiRestController;
import com.reyun.saas.common.restResult.PageParam;
import com.reyun.saas.common.restResult.RestResult;
import com.reyun.saas.mob.user.domain.RtaWhiteList;
import com.reyun.saas.mob.user.service.RtaWhiteListService;
import com.reyun.saas.security.utils.SecurityUtils;
import com.reyun.saas.web.aop.Log;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@Slf4j
@Api(value = "/rta", tags = "rta白名单管理")
@ApiRestController("rta")
public class RtaWhiteListController {

    @Resource
    private RtaWhiteListService rtaWhiteListService;

    @Log(value = 1, description = "rta白名单创建", type = 4,insertDB = true)
    @ApiOperation(value = "rta白名单创建", notes = "前端传参 服务器备注:serverRemarks  很多ip:ips(文本域) ", produces = "application/json")
    @PostMapping("create")
    public RestResult create(@RequestBody Map<String, Object> map) {
        return rtaWhiteListService.create(map, SecurityUtils.getLoginUserId());
    }

    @Log(value = 3, description = "rta白名单修改", type = 4,insertDB = true)
    @ApiOperation(value = "rta白名单修改", produces = "application/json"
            , notes = "rta的id:id 服务备注名:serverRemarks ip:ip 修改时ip不为空或者空字符串为修改ip " +
            "ip为空为修改服务器备注")
    @PutMapping("update")
    public RestResult update(@RequestBody RtaWhiteList source) {
        return rtaWhiteListService.update(source, SecurityUtils.getLoginUserId());
    }

    @Log(value = 3, description = "修改rta白名单启用状态", type = 4,insertDB = true)
    @ApiOperation(value = "修改rta白名单启用状态", notes = "修改rta白名单启用状态", produces = "application/json")
    @PutMapping("updateActive/{rtaId}/{status}")
    public RestResult updateActive(@PathVariable("rtaId") Long rtaId, @PathVariable("status") Boolean status) {
        return rtaWhiteListService.updateActive(rtaId, status, SecurityUtils.getLoginUserId());
    }


    @Log(value = 2, description = "删除rta白名单", type = 4,insertDB = true)
    @ApiOperation(value = "删除rta白名单", notes = "删除rta白名单", produces = "application/json")
    @DeleteMapping("delete/{rtaId}")
    public RestResult deleteRta(@PathVariable("rtaId") Long rtaId) {
        return rtaWhiteListService.deleteRta(rtaId, SecurityUtils.getLoginUserId());
    }


    @Log(value = 4, description = "rta白名单列表", type = 4)
    @ApiOperation(value = "rta白名单列表", notes = "rta白名单列表", produces = "application/json")
    @GetMapping("rtaList")
    public RestResult rtaList(PageParam pageParam) {
        return rtaWhiteListService.list(pageParam, SecurityUtils.getLoginUserId());
    }


}
