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


import com.cf.imes.framework.common.pojo.CommonResult;
import com.cf.imes.module.system.controller.admin.parser.vo.ParserTemplateReqVO;
import com.cf.imes.module.system.controller.admin.parser.vo.ParserTemplateRespVO;
import com.cf.imes.module.system.controller.admin.parser.vo.TemplateLimitReqVO;
import com.cf.imes.module.system.controller.admin.parser.vo.TemplateSimpleRespVO;
import com.cf.imes.module.system.service.parser.ParserTemplateService;
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.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

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

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

@RestController
@RequestMapping("/system/parser-template")
@Tag(name = "管理后台 - 解析器模板管理")
@Validated
public class ParserTemplateController {


    @Resource
    private ParserTemplateService parserTemplateService;


    @PutMapping("")
    @Operation(summary = "解析器模板配置修改")
    public CommonResult<Boolean> updateParserTemplate(@Valid @RequestBody ParserTemplateReqVO reqVO) {
        parserTemplateService.update(reqVO);
        return success(true);
    }




    @GetMapping("")
    @Operation(summary = "获得解析器模板树")
    public CommonResult<Map<Integer, List<ParserTemplateRespVO>>> getParserTemplateTree(@RequestParam(required = false) Long type) {
        return success(parserTemplateService.getParserTemplateTree(type));
    }




    @GetMapping("/simple")
    @Operation(summary = "获得解析对应的精简信息")
    public CommonResult<Map<Integer, List<TemplateSimpleRespVO>>> getParserTemplateSimple(@RequestParam(required = false) Long type) {
        return success(parserTemplateService.getParserTemplateSimple(type));
    }




    @GetMapping("/{id}")
    @Operation(summary = "根据ID获取解析器模板信息")
    @Parameter(name = "id", description = "解析器ID", required = true)
    public CommonResult<ParserTemplateRespVO> getParserTemplate(@PathVariable("id") Long id) {
        return success(parserTemplateService.getParserTemplate(id));
    }





    @PutMapping("/limit")
    @Operation(summary = "修改解析器模板的授权信息")
    public CommonResult<Boolean> updateParserTemplateLimit(@Valid @RequestBody TemplateLimitReqVO reqVO) {
        parserTemplateService.updateParserTemplateLimit(reqVO);
        return success(true);
    }





    @GetMapping("/limit/{organId}")
    @Operation(summary = "获取组织对应的解析器模板的授权信息")
    @Parameter(name = "organId", description = "解析器ID", required = true)
    public CommonResult<List<Long>> getOrganParserTemplateLimit(@PathVariable("organId") Long organId) {
        return success(parserTemplateService.getOrganParserTemplateLimit(organId));
    }



}
