package com.yx.face.controller.admin;

import com.github.pagehelper.PageInfo;
import com.yx.face.boot.component.security.Authority;
import com.yx.face.boot.core.BaseController;
import com.yx.face.boot.restful.RestResponse;
import com.yx.face.boot.restful.RestResult;
import com.yx.face.boot.restful.ServiceException;
import com.yx.face.model.dto.SystemPushConfigDTO;
import com.yx.face.model.vo.SystemPushConfigVO;
import com.yx.face.service.SystemPushConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @description:
 * @ClassName UserWhitelistController
 * @Author WXG
 * @Date 2021/11/5 14:12
 */
@Slf4j
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@Api(tags = "B 数据推送配置")
@RestController
@RequestMapping("admin/sysPush")
public class SystemPushConfigController extends BaseController {

    private final SystemPushConfigService systemPushConfigService;


    @ApiOperation(value = "添加")
    @Authority(value = {1})
    @PostMapping("/add")
    public RestResult<Boolean> add(@RequestBody SystemPushConfigDTO dto) {
        return RestResponse.ok(systemPushConfigService.add(dto, getUserId()));
    }

    @ApiOperation(value = "修改")
    @Authority(value = {1})
    @PostMapping("/update")
    public RestResult<Boolean> update(@RequestBody SystemPushConfigDTO dto) {
        return RestResponse.ok(systemPushConfigService.update(dto, getUserId()));
    }

    @ApiOperation(value = "启用/停用")
    @Authority(value = {1})
    @GetMapping("/updateStatus")
    public RestResult<Boolean> updateStatus(Integer id, Integer status) {
        if (id == null || status == null) {
            throw new ServiceException("参数不全");
        }
        return RestResponse.ok(systemPushConfigService.updateStatus(id, status));
    }

    @ApiOperation(value = "删除")
    @Authority(value = {1})
    @DeleteMapping("/delete")
    public RestResult<Boolean> delete(Integer id) {
        if (id == null) {
            throw new ServiceException("参数不全");
        }
        return RestResponse.ok(systemPushConfigService.delete(id));
    }

    @ApiOperation(value = "列表")
    @Authority(value = {1})
    @GetMapping("/getList")
    public RestResult<PageInfo<SystemPushConfigVO>> getList(@RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
                                                            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                            @RequestParam(name = "accountId", defaultValue = "0") Integer accountId,
                                                            @RequestParam(name = "status", defaultValue = "99") Integer status) {
        PageInfo<SystemPushConfigVO> list = systemPushConfigService.getList(pageNum, pageSize, accountId, status);

        return RestResponse.ok(list);
    }
}
