package com.xueyi.system.digitalmans.controller;

import com.xueyi.common.core.web.result.AjaxResult;
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.security.annotation.RequiresPermissions;
import com.xueyi.common.web.entity.controller.BaseController;
import com.xueyi.system.api.digitalmans.domain.dto.DmModelDto;
import com.xueyi.system.digitalmans.domain.dto.DmModelUploadDto;
import com.xueyi.system.digitalmans.domain.query.DmModelQuery;
import com.xueyi.system.digitalmans.service.IDmModelService;
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("/model")
public class DmModelController extends BaseController<DmModelQuery, DmModelDto, IDmModelService> {

    @Autowired
    IDmModelService modelService;
    /** 定义节点名称 */
    @Override
    protected String getNodeName() {
        return "模型" ;
    }

    /**
     * 查询模型列表
     */
    @Override
    @GetMapping("/list")
    @RequiresPermissions(Auth.DM_MODEL_LIST)
    public AjaxResult list(DmModelQuery dmModel) {
        return super.list(dmModel);
    }

    /**
     * 查询模型详细
     */
    @Override
    @GetMapping(value = "/{id}")
    @RequiresPermissions(Auth.DM_MODEL_SINGLE)
    public AjaxResult getInfo(@PathVariable Serializable id) {
        return super.getInfo(id);
    }

    /**
     * 模型新增
     */
    @Override
    @PostMapping
    @RequiresPermissions(Auth.DM_MODEL_ADD)
    @Log(title = "模型管理", businessType = BusinessType.INSERT)
    public AjaxResult add(@Validated({V_A.class}) @RequestBody DmModelDto dmModel) {
        return super.add(dmModel);
    }

    /**
     * 模型修改
     */
    @Override
    @PutMapping
    @RequiresPermissions(Auth.DM_MODEL_EDIT)
    @Log(title = "模型管理", businessType = BusinessType.UPDATE)
    public AjaxResult edit(@Validated({V_E.class}) @RequestBody DmModelDto dmModel) {
        return super.edit(dmModel);
    }


    /**
     * 上传资源修改
     */
    @PostMapping(value = "/upload_resource")
    @Log(title = "资源管理", businessType = BusinessType.OTHER)
    public AjaxResult uploadResource(@Validated({V_A.class}) @RequestBody DmModelUploadDto modelUploadDto) {

        return toAjax(modelService.uploadResource(modelUploadDto));
    }
    /**
     * 模型批量删除
     */
    @Override
    @DeleteMapping("/batch/{idList}")
    @RequiresPermissions(Auth.DM_MODEL_DEL)
    @Log(title = "模型管理", businessType = BusinessType.DELETE)
    public AjaxResult batchRemove(@PathVariable List<Long> idList) {
        return super.batchRemove(idList);
    }

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

    interface Auth {
        /** 系统 - 模型管理 - 列表 */
        String DM_MODEL_LIST = "model:model:list";
        /** 系统 - 模型管理 - 详情 */
        String DM_MODEL_SINGLE = "model:model:single";
        /** 系统 - 模型管理 - 新增 */
        String DM_MODEL_ADD = "model:model:add";
        /** 系统 - 模型管理 - 修改 */
        String DM_MODEL_EDIT = "model:model:edit";
        /** 系统 - 模型管理 - 删除 */
        String DM_MODEL_DEL = "model:model:delete";
    }
}
