package cn.stylefeng.team.project.modular.maxsort.controller;

import cn.stylefeng.roses.kernel.rule.exception.base.ServiceException;
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
import cn.stylefeng.team.project.api.SystemCodeApi;
import cn.stylefeng.team.project.api.enums.SystemCodeTypeEnum;
import cn.stylefeng.team.project.api.exception.enums.ProjectExceptionEnum;
import cn.stylefeng.team.project.api.pojo.SystemCodeInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@ApiResource(name = "通用的获取DevOps的系统编码")
public class SystemCodeController {

    @Resource
    private SystemCodeApi systemCodeApi;

    @GetResource(name = "获取DevOps系统编码", path = "/devops/getSystemCode")
    public ResponseData<SystemCodeInfo> detail(@RequestParam("systemType") String systemType) {

        SystemCodeTypeEnum systemCodeTypeEnum = SystemCodeTypeEnum.codeToEnum(systemType);

        if (systemCodeTypeEnum == null) {
            throw new ServiceException(ProjectExceptionEnum.DEVOPS_SYSTEM_CODE_TYPE_ERROR);
        }

        SystemCodeInfo newSystemCode = systemCodeApi.createNewSystemCode(systemCodeTypeEnum);

        return new SuccessResponseData<>(newSystemCode);
    }

}
