package com.ecep.contract.service;

import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import org.controlsfx.control.TaskProgressView;
import org.springframework.stereotype.Service;

import com.ecep.contract.Desktop;
import com.ecep.contract.MessageHolder;
import com.ecep.contract.model.CloudRk;
import com.ecep.contract.model.Company;
import com.ecep.contract.task.CloudRkSyncTask;
import com.ecep.contract.vm.CloudRkViewModel;
import com.fasterxml.jackson.annotation.JsonAlias;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import javafx.concurrent.Task;
import lombok.Data;

@Service
public class CloudRkService extends QueryService<CloudRk, CloudRkViewModel> {
    @Data
    @JsonIgnoreProperties(ignoreUnknown = true)
    public static class EntInfo {
        @JsonAlias("entid")
        private String id;
        @JsonAlias("entname")
        private String name;
        private boolean nowName;
    }

    /**
     * 生成定时同步任务
     *
     * @param taskProgressView 任务视图
     */
    public void scheduledTasks(TaskProgressView<Task<?>> taskProgressView) {
        ScheduledExecutorService executorService = Desktop.instance.getExecutorService();
        // 第一次延时1分钟启动
        executorService.schedule(() -> {
            // 定时 30分钟 运行一次
            executorService.scheduleAtFixedRate(() -> {
                Desktop.instance.getTaskMonitorCenter().registerAndStartTask(new CloudRkSyncTask());
            }, 0, 30, TimeUnit.MINUTES);
        }, 1, TimeUnit.MINUTES);
    }

    public CloudRk updateCloudRk(Company company, MessageHolder holder) {
        // TODO Auto-generated method stub
        throw new UnsupportedOperationException("Unimplemented method 'updateCloudRk'");
    }

    public CloudRk getOrCreateCloudRk(Company company) {
        // TODO Auto-generated method stub
        throw new UnsupportedOperationException("Unimplemented method 'getOrCreateCloudRk'");
    }

    public boolean checkBlackListUpdateElapse(Company company, CloudRk cloudRk) {
        // TODO Auto-generated method stub
        throw new UnsupportedOperationException("Unimplemented method 'checkBlackListUpdateElapse'");
    }

    public void updateBlackList(Company company, CloudRk cloudRk) {
        // TODO Auto-generated method stub
        throw new UnsupportedOperationException("Unimplemented method 'updateBlackList'");
    }
}
