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

import com.qqchen.deploy.backend.deploy.entity.RepositoryGroup;
import com.qqchen.deploy.backend.deploy.dto.RepositoryGroupDTO;
import com.qqchen.deploy.backend.deploy.query.RepositoryGroupQuery;
import com.qqchen.deploy.backend.deploy.service.IRepositoryGroupService;
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 jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.concurrent.CompletableFuture;

/**
 * Git仓库组Controller
 */
@Slf4j
@RestController
@RequestMapping("/api/v1/repository-group")
@Tag(name = "Git仓库组管理", description = "Git仓库组管理相关接口")
public class RepositoryGroupApiController extends BaseController<RepositoryGroup, RepositoryGroupDTO, Long, RepositoryGroupQuery> {

    @Resource
    private IRepositoryGroupService repositoryGroupService;

    @Override
    public Response<RepositoryGroupDTO> create(RepositoryGroupDTO dto) {
        return super.create(dto);
    }

    @Override
    public Response<RepositoryGroupDTO> update(Long aLong, RepositoryGroupDTO dto) {
        return super.update(aLong, dto);
    }

    @Override
    public Response<Void> delete(Long aLong) {
        return super.delete(aLong);
    }

    @Override
    public Response<RepositoryGroupDTO> findById(Long aLong) {
        return super.findById(aLong);
    }

    @Override
    public Response<List<RepositoryGroupDTO>> findAll() {
        return super.findAll();
    }

    @Override
    public Response<Page<RepositoryGroupDTO>> page(RepositoryGroupQuery query) {
        return super.page(query);
    }

    @Override
    public Response<List<RepositoryGroupDTO>> findAll(RepositoryGroupQuery query) {
        return super.findAll(query);
    }

    @Override
    public CompletableFuture<Response<Void>> batchProcess(List<RepositoryGroupDTO> dtos) {
        return super.batchProcess(dtos);
    }

    @Operation(summary = "同步Git仓库组", description = "异步同步指定外部系统的所有仓库组，立即返回")
    @PostMapping("/sync")
    public Response<Void> sync(
        @Parameter(description = "外部系统ID", required = true) @RequestParam Long externalSystemId
    ) {
        repositoryGroupService.syncGroups(externalSystemId);
        return Response.success();
    }

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

    }
}