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

import com.qqchen.deploy.backend.deploy.dto.TeamEnvironmentConfigDTO;
import com.qqchen.deploy.backend.deploy.entity.TeamEnvironmentConfig;
import com.qqchen.deploy.backend.deploy.query.TeamEnvironmentConfigQuery;
import com.qqchen.deploy.backend.deploy.service.ITeamEnvironmentConfigService;
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.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 团队环境配置Controller
 *
 * @author qqchen
 * @since 2025-11-04
 */
@Slf4j
@RestController
@RequestMapping("/api/v1/team-environment-config")
@Tag(name = "团队环境配置管理", description = "团队环境配置相关接口")
public class TeamEnvironmentConfigApiController extends BaseController<TeamEnvironmentConfig, TeamEnvironmentConfigDTO, Long, TeamEnvironmentConfigQuery> {

    private final ITeamEnvironmentConfigService teamEnvironmentConfigService;

    public TeamEnvironmentConfigApiController(ITeamEnvironmentConfigService service) {
        this.teamEnvironmentConfigService = service;
    }

    @Operation(summary = "根据团队ID查询环境配置列表")
    @GetMapping("/team/{teamId}")
    public Response<List<TeamEnvironmentConfigDTO>> getByTeamId(
            @Parameter(description = "团队ID", required = true) @PathVariable Long teamId
    ) {
        return Response.success(teamEnvironmentConfigService.findByTeamId(teamId));
    }

    @Operation(summary = "根据团队ID和环境ID查询配置")
    @GetMapping("/team/{teamId}/environment/{environmentId}")
    public Response<TeamEnvironmentConfigDTO> getByTeamIdAndEnvironmentId(
            @Parameter(description = "团队ID", required = true) @PathVariable Long teamId,
            @Parameter(description = "环境ID", required = true) @PathVariable Long environmentId
    ) {
        return Response.success(teamEnvironmentConfigService.findByTeamIdAndEnvironmentId(teamId, environmentId));
    }

    @Operation(summary = "检查配置是否存在")
    @GetMapping("/exists")
    public Response<Boolean> exists(
            @Parameter(description = "团队ID", required = true) @RequestParam Long teamId,
            @Parameter(description = "环境ID", required = true) @RequestParam Long environmentId
    ) {
        return Response.success(teamEnvironmentConfigService.exists(teamId, environmentId));
    }

    @Override
    protected void exportData(jakarta.servlet.http.HttpServletResponse response, List<TeamEnvironmentConfigDTO> data) {
        // TODO: 实现导出功能
    }
}

