package com.qqchen.deploy.backend.deploy.api;

import com.qqchen.deploy.backend.deploy.dto.BuildConfigDefinedDTO;
import com.qqchen.deploy.backend.deploy.dto.DeployAppBuildDTO;
import com.qqchen.deploy.backend.deploy.dto.DeployAppConfigDTO;
import com.qqchen.deploy.backend.deploy.entity.DeployAppConfig;
import com.qqchen.deploy.backend.deploy.query.DeployAppConfigQuery;
import com.qqchen.deploy.backend.deploy.service.IDeployAppConfigService;
import com.qqchen.deploy.backend.framework.api.Response;
import com.qqchen.deploy.backend.framework.controller.BaseController;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 应用配置控制器
 */
@Slf4j
@RestController
@RequestMapping("/api/v1/deploy-app-config")
@Tag(name = "应用配置管理", description = "应用配置管理相关接口")
public class DeployAppConfigApiController extends BaseController<DeployAppConfig, DeployAppConfigDTO, Long, DeployAppConfigQuery> {


    @Resource
    private IDeployAppConfigService deployAppConfigService;

    @Operation(summary = "获取构建类型Schema定义")
    @GetMapping("/defined")
    public Response<List<BuildConfigDefinedDTO>> defined() {
        return Response.success(deployAppConfigService.defined());
    }

    @Override
    protected void exportData(HttpServletResponse response, List<DeployAppConfigDTO> data) {

    }

    @Operation(summary = "部署服务")
    @PostMapping("/deploy")
    public Response<Void> deploy(@Validated @RequestBody DeployAppBuildDTO dto) {
        deployAppConfigService.deploy(dto);
        return Response.success();
    }
}