/// class PD.Manage.Modules.ObjectModel.ProcessDeleteCommand

PD.Manage.Modules.ObjectModel.ProcessDeleteCommand =
PD.Commands.Command.extend({

    //===================================
    // PUBLIC METHODS
    //===================================

    setDefaults: function () {

        this.props("id", "process/delete");
        this.props("enabled", true);
        this.props("icon", PD.Path.to16x16("DELETE.PNG"));
        this.props("label", "Delete");
        this.props("tooltip", "Delete the selected Process.");

        this.state("processId", null);
        this.state("processName", null);

    },

    setState: function (state) {
        this._super(state);
        this.props("enabled", this.state("processId") != null)
    },

    execute: function (e) {
        this._super(e);

        let processId = this.state("processId");
        let processName = this.state("processName");

        Jade.UI.MessageDialog.open({
            dialogStyle: Jade.UI.MessageDialogStyle.Warning,
            dialogButtons: Jade.UI.MessageDialogButtonStyle.OKCancel,
            allowClose: true,
            title: "Delete Process",
            message: `Delete the ${processName} process?`,
            select: (e) => {
                e.close();
                if (e.button === Jade.UI.MessageDialogButton.ok) {
                    this._executeDeletion(processId);
                }
            }
        });

    },

    //===================================
    // PRIVATE METHODS
    //===================================

    _executeDeletion: function (processId) {

        var service = new PD.Manage.Services.ProcessService();

        service.deleteProcess(processId, (data) => {

            PD.context
                .get_default()
                .get_commands()
                .setState({
                    processId: null,
                    processName: null
                });

            PD.context
                .get_default()
                .get_events()
                .publish("process/delete", {
                    id: processId
                });

        });

    }

});