package com.usky.issue.controller.web;

import com.usky.common.core.bean.ApiResult;
import com.usky.issue.service.vo.ManualSyncRequest;
import com.usky.issue.service.vo.SyncStatusResponse;
import com.usky.issue.service.vo.SyncTaskResponse;
import com.usky.issue.service.CloudSyncService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 云平台数据同步接口
 *
 * @author fyc
 * @date 2026-05-21
 */
@RestController
@Validated
@RequestMapping("/cloud")
public class CloudSyncController {

    @Autowired
    private CloudSyncService cloudSyncService;

    @GetMapping("/sync/status")
    public ApiResult<List<SyncStatusResponse>> listStatus() {
        return ApiResult.success(cloudSyncService.listSyncStatus());
    }

    @PostMapping("/sync")
    public ApiResult<SyncTaskResponse> manualSync(@RequestBody ManualSyncRequest request) {
        return ApiResult.success(cloudSyncService.triggerManualSync(request.getType(), request.getDirection()));
    }

    @GetMapping("/sync/task/{taskId}")
    public ApiResult<SyncTaskResponse> taskProgress(@PathVariable Long taskId) {
        return ApiResult.success(cloudSyncService.getTaskProgress(taskId));
    }
}
