package com.cf.imes.module.system.controller.admin.machine;

import com.cf.imes.framework.common.pojo.CommonResult;
import com.cf.imes.framework.common.pojo.PageParam;
import com.cf.imes.framework.common.pojo.PageResult;
import com.cf.imes.framework.common.util.object.BeanUtils;
import com.cf.imes.framework.operatelog.core.annotations.OperateLog;
import com.cf.imes.module.system.controller.admin.machine.vo.*;
import com.cf.imes.module.system.dal.dataobject.machinetemplate.MachineTemplateDO;
import com.cf.imes.module.system.service.machine.MachineTemplateService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import java.util.List;
import java.util.Map;

import static com.cf.imes.framework.common.pojo.CommonResult.success;

/**
 * @author there
 */
@RestController
@RequestMapping("/system/machine-template")
@Tag(name = "机台模板")
@Validated
public class MachineTemplateController {

    @Resource
    private MachineTemplateService machineTemplateService;

    @GetMapping("/setDefaultTemplate")
    @Operation(summary = "设置默认机台模板")
    @PreAuthorize("@ss.hasPermission('machine-template::create')")
    public CommonResult<Boolean> setDefaultTemplate(@RequestParam Long id) {
        return success(machineTemplateService.setDefaultTemplate(id));
    }

    @GetMapping("getMachineTemplateTree")
    @Operation(summary = "获得机台模板树")
    @PreAuthorize("@ss.hasPermission('machine-template::query')")
    public CommonResult<Map<Integer, List<MachineTemplateDO>>> getMachineTemplateTree() {
        return success(machineTemplateService.getMachineTemplateTree());
    }


    @GetMapping("page-template-machine")
    @Operation(summary = "机台模板分页")
    @PreAuthorize("@ss.hasPermission('machine-template::query')")
    public CommonResult<PageResult<MachineTemplateDO>> pageTemplateById(MachinePageReqVO pageParam) {
        return success(machineTemplateService.page(pageParam));
    }


    @PutMapping("cutting-machine")
    @Operation(summary = "新增机台模板配置")
    @PreAuthorize("@ss.hasPermission('machine-template::create')")
    @OperateLog(logArgs = false)
    public CommonResult<Long> createCuttingTemplate(@RequestBody CuttingTemplateSaveReqVO reqVO) {
        return success(machineTemplateService.createCuttingTemplate(reqVO));
    }

    @PostMapping("cutting-machine")
    @Operation(summary = "修改机台模板配置")
    @PreAuthorize("@ss.hasPermission('machine-template::update')")
    @OperateLog(logArgs = false)
    public CommonResult<Boolean> updateCuttingTemplate(@RequestBody CuttingTemplateSaveReqVO reqVO) {
        return success(machineTemplateService.updateCuttingTemplate(reqVO));
    }

    @GetMapping("cutting-machine")
    @Operation(summary = "获取机台模板配置")
    @PreAuthorize("@ss.hasPermission('machine-template::query')")
    public CommonResult<CuttingTemplateRespVO> getCuttingTemplateById(@RequestParam("id") String id) {
        return success(machineTemplateService.getCuttingTemplateById(id));
    }

    @DeleteMapping("cutting-machine")
    @Operation(summary = "删除机台模板配置")
    @PreAuthorize("@ss.hasPermission('machine-template::delete')")
    public CommonResult<Boolean> deleteCutting(@RequestParam("id") Long id) {
        return success(machineTemplateService.deleteCuttingTemplate(id));
    }

    @DeleteMapping("batch-delete-cutting")
    @Operation(summary = "批量删除机台模板配置")
    @PreAuthorize("@ss.hasPermission('machine-template::delete')")
    public CommonResult<Boolean> batchDeleteCutting(@RequestParam("id") List<Long> ids) {
        return success(machineTemplateService.batchDeleteCuttingTemplate(ids));
    }






}
