package com.lanyuanxiaoyao.service.info.controller;

import com.lanyuanxiaoyao.service.common.entity.SyncState;
import com.lanyuanxiaoyao.service.info.service.SyncStateService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * Sync State
 *
 * @author lanyaunxiaoyao
 * @date 2024-01-03
 */
@RestController
@RequestMapping("/info")
public class SyncStateController {
    private static final Logger logger = LoggerFactory.getLogger(SyncStateController.class);

    private final SyncStateService syncStateService;

    public SyncStateController(SyncStateService syncStateService) {
        this.syncStateService = syncStateService;
    }

    @GetMapping("/sync_state/detail")
    public SyncState syncState(@RequestParam("flink_job_id") Long flinkJobId, @RequestParam("alias") String alias) {
        return syncStateService.syncState(flinkJobId, alias);
    }

    @GetMapping("/sync_state/save_compaction_id")
    public void saveCompactionId(
            @RequestParam("flink_job_id") Long flinkJobId,
            @RequestParam("alias") String alias,
            @RequestParam("application_id") String applicationId
    ) {
        syncStateService.saveCompactionApplicationId(flinkJobId, alias, applicationId);
    }
}
