package com.ecep.contract.controller;

import java.time.LocalDateTime;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.ecep.contract.Desktop;
import com.ecep.contract.model.CloudYu;
import com.ecep.contract.model.Company;
import com.ecep.contract.service.YongYouU8Service;
import com.ecep.contract.task.ContractSyncTask;
import com.ecep.contract.task.CustomerSyncTask;
import com.ecep.contract.task.EmployeesSyncTask;
import com.ecep.contract.task.VendorSyncTask;
import com.ecep.contract.util.FxmlPath;
import com.ecep.contract.util.UITools;
import com.ecep.contract.vm.CloudYuInfoViewModel;

import javafx.event.ActionEvent;
import javafx.scene.control.TableColumn;
import javafx.stage.Stage;

@Lazy
@Scope("prototype")
@Component
@FxmlPath("/ui/cloud/u8_manager.fxml")
public class YongYouU8ManagerWindowController
        extends AbstManagerWindowController<CloudYu, CloudYuInfoViewModel, YongYouU8ManagerSkin> {
    private static final Logger logger = LoggerFactory.getLogger(YongYouU8ManagerWindowController.class);

    public static void show() {
        show(YongYouU8ManagerWindowController.class, null);
    }

    public TableColumn<CloudYuInfoViewModel, Number> idColumn;
    public TableColumn<CloudYuInfoViewModel, LocalDateTime> latestUpdateColumn;
    public TableColumn<CloudYuInfoViewModel, Company> companyColumn;
    public TableColumn<CloudYuInfoViewModel, String> cloudIdColumn;
    public TableColumn<CloudYuInfoViewModel, LocalDateTime> cloudLatestColumn;
    public TableColumn<CloudYuInfoViewModel, String> descriptionColumn;

    @Override
    public YongYouU8Service getViewModelService() {
        return getSkin().getU8Service();
    }

    @Override
    protected YongYouU8ManagerSkin createDefaultSkin() {
        return new YongYouU8ManagerSkin(this);
    }

    @Override
    public void show(Stage stage) {
        super.show(stage);
        getTitle().set("用友U8");
    }

    /**
     * 打开配置窗口
     */
    public void onConfigAction(ActionEvent event) {
        BaseController.show(YongYouU8ConfigWindowController.class, null);
    }

    public void onPersonSyncAction(ActionEvent event) {
        EmployeesSyncTask task = new EmployeesSyncTask();
        UITools.showTaskDialogAndWait("员工数据同步", task, null);
    }

    public void onContractSyncAction(ActionEvent event) {
        ContractSyncTask task = new ContractSyncTask();
        UITools.showTaskDialogAndWait("合同数据增量同步", task, null);
    }

    public void onContractAllSyncAction(ActionEvent event) {
        ContractSyncAllTask task = new ContractSyncAllTask();
        UITools.showTaskDialogAndWait("合同数据全量同步", task, null);
    }

    public void onVendorSyncAction(ActionEvent event) {
        VendorSyncTask task = new VendorSyncTask();
        UITools.showTaskDialogAndWait("供应商数据同步", task, null);
    }

    public void onCustomerSyncAction(ActionEvent event) {
        CustomerSyncTask task = new CustomerSyncTask();
        UITools.showTaskDialogAndWait("客户数据同步", task, null);
    }

    public void onContractGroupSyncAction(ActionEvent event) {
        ContractGroupSyncTask task = new ContractGroupSyncTask();
        Desktop.instance.getTaskMonitorCenter().registerAndStartTask(task);
    }

    public void onContractTypeSyncAction(ActionEvent event) {
        ContractTypeSyncTask task = new ContractTypeSyncTask();
        Desktop.instance.getTaskMonitorCenter().registerAndStartTask(task);
    }

    public void onContractKindSyncAction(ActionEvent event) {
        ContractKindSyncTask task = new ContractKindSyncTask();
        Desktop.instance.getTaskMonitorCenter().registerAndStartTask(task);
    }

    public void onVendorClassSyncAction(ActionEvent event) {
        VendorClassSyncTask task = new VendorClassSyncTask();
        Desktop.instance.getTaskMonitorCenter().registerAndStartTask(task);
    }

    public void onCustomerClassSyncAction(ActionEvent event) {
        CustomerClassSyncTask task = new CustomerClassSyncTask();
        Desktop.instance.getTaskMonitorCenter().registerAndStartTask(task);
    }

}
