package com.casic.missiles.controller.system.message;

import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.ObjectUtil;
import com.casic.missiles.dto.ReturnDTO;
import com.casic.missiles.dto.system.UserClientDTO;
import com.casic.missiles.enums.BusinessExceptionEnum;
import com.casic.missiles.exception.BusinessException;
import com.casic.missiles.model.system.UserPush;
import com.casic.missiles.service.system.IMessagePushService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@Api(tags = "App推送接口")
@AllArgsConstructor
@RequestMapping("/push")
public class MessagePushController {

    private final IMessagePushService messagePushService;


    @ApiOperation("推送注册")
    @PostMapping("/app/registerGeTui")
    public ReturnDTO geTuiRegister(@RequestBody @Valid UserClientDTO userClientDTO) {
        Assert.isFalse(StringUtils.isEmpty(userClientDTO.getClientId()), () -> {
            throw new BusinessException(BusinessExceptionEnum.CLIENT_ID_EMPTY);
        });
        return messagePushService.registerGeTui(userClientDTO.getClientId());
    }


    @ApiOperation("设置推送启动/停止")
    @PostMapping("/app/enable")
    public ReturnDTO setEnable(@RequestBody @Valid UserClientDTO userClientDTO){
        Assert.isFalse(ObjectUtil.isEmpty(userClientDTO.getEnable()), () -> {
            throw new BusinessException(BusinessExceptionEnum.USER_ID_EMPTY);
        });
        return messagePushService.setEnable(userClientDTO.getEnable());
    }

    @ApiOperation("推送查询")
    @PostMapping("/app/detail")
    public ReturnDTO<UserPush>  getUserPush() {
        return messagePushService.getUserPush();
    }

}
