package com.ecep.contract.controller.company;

import java.time.LocalDate;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.ecep.contract.controller.AbstManagerWindowController;
import com.ecep.contract.model.Company;
import com.ecep.contract.service.CompanyService;
import com.ecep.contract.task.CompanyFilesRebuildTasker;
import com.ecep.contract.util.FxmlPath;
import com.ecep.contract.util.UITools;
import com.ecep.contract.vm.CompanyViewModel;

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

@Lazy
@Scope("prototype")
@Component
@FxmlPath("/ui/company/company-manager.fxml")
public class CompanyManagerWindowController
        extends AbstManagerWindowController<Company, CompanyViewModel, CompanyManagerSkin> {

    // columns
    @FXML
    public TableColumn<CompanyViewModel, Number> idColumn;
    @FXML
    public TableColumn<CompanyViewModel, String> nameColumn;
    @FXML
    public TableColumn<CompanyViewModel, String> uniscidColumn;
    @FXML
    public TableColumn<CompanyViewModel, String> entStatusColumn;
    @FXML
    public TableColumn<CompanyViewModel, LocalDate> createdColumn;
    @FXML
    public TableColumn<CompanyViewModel, String> memoColumn;

    @Autowired
    private CompanyService companyService;

    @Override
    public CompanyService getViewModelService() {
        return companyService;
    }

    @Override
    public void show(Stage stage) {
        super.show(stage);
        getTitle().set("公司管理");
    }

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

    public void onCompanyCreateNewAction(ActionEvent event) {
        getSkin().onTableCreateNewAction(event);
    }

    /**
     * 对所有公司的文件进行重置
     * <p>
     * 弹出对话框模式，对话框中有进度条和重置的消息
     *
     * @param event 事件
     */
    public void onReBuildFilesAction(ActionEvent event) {
        CompanyFilesRebuildTasker task = new CompanyFilesRebuildTasker();
        UITools.showTaskDialogAndWait("公司文件重置", task, null);
    }

    public void onVerifyAction(ActionEvent event) {
        show(CompanyVerifyWindowController.class, null);
    }
}
