package com.ecep.contract.controller.inventory;

import java.time.LocalDate;
import java.time.LocalDateTime;

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.Inventory;
import com.ecep.contract.model.InventoryCatalog;
import com.ecep.contract.service.InventoryService;
import com.ecep.contract.task.InventorySyncTask;
import com.ecep.contract.util.FxmlPath;
import com.ecep.contract.util.UITools;
import com.ecep.contract.vm.InventoryViewModel;

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

@Lazy
@Scope("prototype")
@Component
@FxmlPath(value = "/ui/inventory/inventory-manager.fxml")
public class InventoryManagerWindowController
        extends AbstManagerWindowController<Inventory, InventoryViewModel, InventoryManagerSkin> {

    @FXML
    public TableColumn<InventoryViewModel, Number> idColumn;
    @FXML
    public TableColumn<InventoryViewModel, String> nameColumn;
    @FXML
    public TableColumn<InventoryViewModel, String> codeColumn;
    @FXML
    public TableColumn<InventoryViewModel, InventoryCatalog> catalogColumn;
    @FXML
    public TableColumn<InventoryViewModel, String> specificationColumn;
    @FXML
    public TableColumn<InventoryViewModel, String> unitColumn;
    @FXML
    public TableColumn<InventoryViewModel, Number> purchaseTaxRateColumn;
    @FXML
    public TableColumn<InventoryViewModel, Number> purchasePriceColumn;
    @FXML
    public TableColumn<InventoryViewModel, Number> saleTaxRateColumn;
    @FXML
    public TableColumn<InventoryViewModel, Number> salePriceColumn;
    @FXML
    public TableColumn<InventoryViewModel, LocalDate> createTimeColumn;
    @FXML
    public TableColumn<InventoryViewModel, LocalDateTime> updateDateColumn;
    @FXML
    public TableColumn<InventoryViewModel, String> descriptionColumn;

    @Autowired
    private InventoryService service;

    @Override
    public InventoryService getViewModelService() {
        return service;
    }

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

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

    public void onSyncAction(ActionEvent event) {
        InventorySyncTask task = new InventorySyncTask();
        UITools.showTaskDialogAndWait("同步数据", task, null);
    }

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


}
