package com.xueyi.system.version.controller;

import com.xueyi.common.core.web.result.AjaxResult;
import com.xueyi.common.core.web.result.R;
import com.xueyi.common.core.web.validate.V_A;
import com.xueyi.common.core.web.validate.V_E;
import com.xueyi.common.log.annotation.Log;
import com.xueyi.common.log.enums.BusinessType;
import com.xueyi.common.mqtt.connection.MqttTemplate;
import com.xueyi.common.security.annotation.RequiresPermissions;
import com.xueyi.common.web.entity.controller.BaseController;
import com.xueyi.message.api.transfer.domain.vo.DmDeployScheduleVo;
import com.xueyi.system.api.digitalmans.domain.dto.DmManDeviceDto;
import com.xueyi.system.api.organize.domain.dto.SysEnterpriseDto;
import com.xueyi.system.digitalmans.controller.DmDigitalmanExtController;
import com.xueyi.system.version.domain.dto.DmApkVersionDto;
import com.xueyi.system.version.domain.dto.DmReleaseManagerDto;
import com.xueyi.system.version.domain.query.DmReleaseManagerQuery;
import com.xueyi.system.version.service.IDmReleaseManagerService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.List;

/**
 * 发布管理管理 业务处理
 *
 * @author xueyi
 */
@RestController
@RequestMapping("/releaseManager")
public class DmReleaseManagerController extends BaseController<DmReleaseManagerQuery, DmReleaseManagerDto, IDmReleaseManagerService> {

    private static final Logger log = LoggerFactory.getLogger(DmReleaseManagerController.class);
    @Autowired
    MqttTemplate mqttTemplate;

    /** 定义节点名称 */
    @Override
    protected String getNodeName() {
        return "发布管理" ;
    }

    /** 根据设备id获取数字人信息 */
    @PostMapping("/inner/reply")
    R<Integer> syncDeployStatus(@RequestBody DmDeployScheduleVo vo) {
        log.info(vo.toString());

        return R.ok(baseService.syncDeployStatusByDevId(vo));
    }

    /**
     * 查询发布管理列表
     */
    @Override
    @GetMapping("/list")
    @RequiresPermissions(Auth.DM_MAN_DEVICE_LIST)
    public AjaxResult list(DmReleaseManagerQuery releaseManager) {
        return super.list(releaseManager);
    }

    /**
     * 查询发布管理详细
     */
    @Override
    @GetMapping(value = "/{id}")
    @RequiresPermissions(Auth.DM_MAN_DEVICE_SINGLE)
    public AjaxResult getInfo(@PathVariable Serializable id) {
        return success(super.baseService.selectHistoryByDevId(id));
    }

    @PostMapping("/batch/remote/{idList}")
    @Log(title = "数字人升级", businessType = BusinessType.OTHER)
    public AjaxResult batchRemoteDeploy(@PathVariable List<String> idList, @RequestParam("apkVersion") String apkVersion) {
        return success(baseService.remoteDeployByDevId(idList, apkVersion));
    }

    /**
     * 获取发布管理选择框列表
     */
    @Override
    @GetMapping("/option")
    public AjaxResult option() {
        return super.option();
    }

    interface Auth {
        /** 系统 - 发布管理管理 - 列表 */
        String DM_MAN_DEVICE_LIST = "version:releaseManager:list";
        /** 系统 - 发布管理管理 - 详情 */
        String DM_MAN_DEVICE_SINGLE = "version:releaseManager:single";
    }
}
