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.framework.operatelog.core.annotations.OperateLog;
import com.cf.imes.module.system.controller.admin.machine.vo.*;
import com.cf.imes.module.system.service.machine.MachineService;
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.*;

import jakarta.annotation.Resource;
import java.util.List;
import java.util.Map;

import static com.cf.imes.framework.common.pojo.CommonResult.success;
import static com.cf.imes.framework.operatelog.core.enums.OperateTypeEnum.CREATE;
import static com.cf.imes.framework.operatelog.core.enums.OperateTypeEnum.UPDATE;

/**
 * @author Beal
 */
@RestController
@Tag(name = "组织机台授权")
@RequestMapping("/system/machine-auth")
public class MachineAuthController {
    
    @Resource
    private MachineService machineService;


    @PutMapping("insert-organ-auth")
    @OperateLog(type = CREATE)
    @Operation(summary = "组织机台授权信息新增")
    @PreAuthorize("@ss.hasPermission('machine-auth::create')")
    public CommonResult<Boolean> authInsert(@RequestBody MachineOrgAuthReq vo) {
        return success(machineService.authInsert(vo));
    }


    @PostMapping("update-organ-auth")
    @Operation(summary = "修改组织机台数量")
    @OperateLog(type = UPDATE)
    @PreAuthorize("@ss.hasPermission('machine-auth::update')")
    public CommonResult<Boolean> authUpdate(@RequestBody MachineOrgAuthReq vo) {
        return success(machineService.authUpdate(vo));
    }

    @GetMapping("organ-page")
    @Operation(summary = "组织机台授权分页列表")
    @PreAuthorize("@ss.hasPermission('machine-auth::query')")
    public CommonResult<PageResult<OrganMachineResp>> organTemplatePage(OrganMachinePage page) {
        return success(machineService.organMachinePage(page));
    }

    @GetMapping("organ-by-organId")
    @Operation(summary = "根据组织ID查询已经授权的机台ID")
//    @PreAuthorize("@ss.hasPermission('machine-auth::query')")
    @Parameter(name = "organId", description = "组织id", required = true, example = "1")
    public CommonResult<List<Integer>> organTemplateByOrganId(@RequestParam Long organId ) {
        return success(machineService.organMachineByOrganId(organId));
    }

    @GetMapping("select-machine-auth")
    @Operation(summary = "查询机台授权列表")
//    @PreAuthorize("@ss.hasPermission('machine-auth::query')")
    public CommonResult<Map<Integer, List<MachineBrandModelRespVO>>> getTemplateAuth(MachinePageReqVO pageParam) {

        return success(machineService.getTemplateAuth(pageParam));

    }
    
}
