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

import com.cf.imes.framework.common.pojo.CommonResult;
import com.cf.imes.framework.common.pojo.PageResult;
import com.cf.imes.module.system.controller.admin.machine.vo.OrganTemplatePage;
import com.cf.imes.module.system.controller.admin.machine.vo.OrganTemplateResp;
import com.cf.imes.module.system.controller.admin.machine.vo.TemplateAutoResp;
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.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import jakarta.annotation.Resource;

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

/**
 * @author Beal
 */
@RestController
@Tag(name = "机台模板授权")
@RequestMapping("/system/machine-template-auth")
public class MachineTemplateAuthController {

    @Resource
    private MachineTemplateService machineTemplateService;



    @GetMapping("organ-template-page")
    @Operation(summary = "组织模板授权分页列表")
    @PreAuthorize("@ss.hasPermission('machine-template-auth::query')")
    public CommonResult<PageResult<OrganTemplateResp>> organTemplatePage(OrganTemplatePage page) {
        return success(machineTemplateService.organTemplatePage(page));
    }

    @GetMapping("organ-template-by-organId")
    @Operation(summary = "根据组织id查询组织模板授权")
    @PreAuthorize("@ss.hasPermission('machine-template-auth:query')")
    @Parameter(name = "organId", description = "组织id", required = true, example = "1")
    public CommonResult<OrganTemplateResp> organTemplateByOrganId(@RequestParam Long organId ) {
        return success(machineTemplateService.organTemplateByOrganId(organId));
    }

    @GetMapping("organ-template-machine-auth")
    @Operation(summary = "查询机台模板授权信息")
    @Parameter(name = "organId", description = "组织id", required = true, example = "1")
    @PreAuthorize("@ss.hasPermission('machine-template-auth::query')")
    public CommonResult<TemplateAutoResp> getTemplateAuth(@RequestParam(required = false) Long organId ) {
        return success(machineTemplateService.getTemplateAuth(organId));

    }
}
