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.ParserReqVO;
import com.cf.imes.module.system.controller.admin.parser.vo.ParserRespVO;
import com.cf.imes.module.system.controller.admin.parser.vo.ParserSimpleRespVO;
import com.cf.imes.module.system.service.parser.ParserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
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;

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



    @Resource
    private ParserService parserService;




    @PutMapping("")
    @Operation(summary = "解析器配置修改")
    @PreAuthorize("@ss.hasPermission('base:advertisement:update')")
    public CommonResult<Boolean> updateParser(@Valid @RequestBody ParserReqVO reqVO) {
        parserService.update(reqVO);
        return success(true);
    }




    @GetMapping("")
    @Operation(summary = "获得解析器树")
    @PreAuthorize("@ss.hasAnyPermissions('system:machine:query','system:base-setting')")
    public CommonResult<Map<Integer, List<ParserRespVO>>> getParserTree(@RequestParam(required = false) Long type) {
        return success(parserService.getParserTree(type));
    }



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




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




}
