/// class PD.Manage.Modules.ObjectModel.EntityTypeDeleteCommand

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

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

    setDefaults: function () {

        this.props("id", "entity-type/delete");
        this.props("enabled", true);
        this.props("icon", PD.Path.to16x16("DELETE.PNG"));
        this.props("label", "Delete");
        this.props("tooltip", "Delete the selected Entity Type.");

        this.state("entityTypeId", null);
        this.state("entityTypeName", null);

    },

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

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

        let entityTypeId = this.state("entityTypeId");
        let entityTypeName = this.state("entityTypeName");

        Jade.UI.MessageDialog.open({
            dialogButtons: Jade.UI.MessageDialogButtonStyle.OKCancel,
            dialogStyle: Jade.UI.MessageDialogStyle.Warning,
            title: "Delete Entity Type",
            message: `Delete the "${entityTypeName}" entity type?`,
            select: (e) => {
                if (e.button == Jade.UI.MessageDialogButton.ok) {
                    this._executeDeletion(e, entityTypeId)
                }
                e.close();
            }
        });

    },

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

    _executeDeletion: function (e, entityTypeId) {

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

        service.deleteEntityType(entityTypeId, function (data) {
            PD.context.get_default().get_events().publish("entity-type/delete", {
                id: entityTypeId
            });
        });

    }

});