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

import com.qqchen.deploy.backend.deploy.entity.ExternalSystem;
import com.qqchen.deploy.backend.framework.api.Response;
import com.qqchen.deploy.backend.framework.controller.BaseController;
import com.qqchen.deploy.backend.system.model.ExternalSystemDTO;
import com.qqchen.deploy.backend.system.model.query.ExternalSystemQuery;
import com.qqchen.deploy.backend.deploy.service.IExternalSystemService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
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.web.bind.annotation.*;

import java.util.List;

/**
 * 外部系统管理API控制器
 * 提供外部系统的REST接口，包括：
 * 1. 基础CRUD操作
 * 2. 连接测试
 * 3. 数据同步
 * 4. 状态管理
 *
 * @author QQChen
 * @version 1.0.0
 */
@Slf4j
@RestController
@RequestMapping("/api/v1/external-system")
@Tag(name = "第三方系统管理API", description = "对外提供的第三方系统管理接口")
public class ExternalSystemApiController extends BaseController<ExternalSystem, ExternalSystemDTO, Long, ExternalSystemQuery> {

    @Resource
    private IExternalSystemService externalSystemService;

    @Operation(summary = "测试连接")
    @GetMapping("/{id}/test-connection")
    public Response<Boolean> testConnection(
        @Parameter(description = "系统ID", required = true) @PathVariable Long id
    ) {
        return Response.success(externalSystemService.testConnection(id));
    }

    @Operation(summary = "更新状态")
    @PutMapping("/{id}/status")
    public Response<Void> updateStatus(
        @Parameter(description = "系统ID", required = true) @PathVariable Long id,
        @Parameter(description = "是否启用", required = true) @RequestParam boolean enabled
    ) {
        externalSystemService.updateStatus(id, enabled);
        return Response.success();
    }

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