package com.backendsys.controller.Ali;

import com.backendsys.entity.Ali.AliDashscopeTaskDTO;
import com.backendsys.entity.PageDTO;
import com.backendsys.service.Ali.AliDashscopeTaskService;
import com.backendsys.utils.response.Result;
import com.backendsys.utils.response.ResultEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Validated
@RestController
@RequestMapping("/api/ali/dashscope")
public class AliDashscopeTaskController {

    @Autowired
    private AliDashscopeTaskService aliDashscopeTaskService;

    @PreAuthorize("@sr.hasPermission('32')")
    @GetMapping("getTaskList")
    public Result aliDashscopeGetTask(@Validated PageDTO pageDTO, @Validated AliDashscopeTaskDTO aliDashscopeTaskDTO) {
        return Result.success(aliDashscopeTaskService.getTaskList(pageDTO.getPage_num(), pageDTO.getPage_size(), aliDashscopeTaskDTO));
    }

    @PreAuthorize("@sr.hasPermission('32')")
    @GetMapping("getTaskDetail")
    public Result getArticleCategoryDetail(@Validated(AliDashscopeTaskDTO.Detail.class) AliDashscopeTaskDTO aliDashscopeTaskDTO) {

        // 判断是否存在
        Map<String, Object> response = aliDashscopeTaskService.getTaskDetail(aliDashscopeTaskDTO);
        if (response == null) {
            return Result.error(ResultEnum.NOT_FOUND.getCode(), ResultEnum.NOT_FOUND.getMessage());
        }

        return Result.success(response);
    }

}
