# `MishkaInstaller.Event.Event`
[🔗](https://github.com/mishka-group/mishka_installer/blob/v0.1.5/lib/event/event.ex#L1)

The `MishkaInstaller.Event.Event` module is the core of events, which comprises pre-prepared
strategies for the implementation and management of plugins introduced to the system
around various events.
These implementation and management strategies are included in the Event module.

> #### Use cases information {: .tip}
>
> The fundamental criteria of the same system serve as the basis for the specification of
> these strategies, which are aimed at common systems.
> Therefore, you are not permitted to utilize this module if you believe that
> your technique is different.

In addition, it is important to remember that the other part of this module is
connected to the queries that are required to be made to the **Erlang runtime database**,
which is known as `Mnesia`.

Using this functionality, you will be able to store the information that is
associated with each plugin in it.

> Note that all storages are based on the name of an event. See `MishkaInstaller.Event.Hook` module.

---

> #### Security considerations {: .warning}
>
> It is important to remember that all of the functionalities contained within this
> section must be implemented at the **high access level**, and they should not directly take
> any input from the user. Ensure that you include the required safety measures.
>
> This module is a read-only in-memory storage optimized for the fastest possible read times
> not for write strategies.

### Note:

When you are writing, you should always make an effort to be more careful because
you might get reconditioned during times of high traffic.
When it comes to reading and running all plugins, this problem only occurs when a
module is being created and destroyed during the compilation process.

# `builder_entry`

```elixir
@type builder_entry() :: {:root, struct() | map(), :edit} | struct() | map()
```

# `error_return`

```elixir
@type error_return() ::
  {:error, [%{action: atom(), field: atom(), message: String.t()}]}
```

# `okey_return`

```elixir
@type okey_return() :: {:ok, struct() | map() | module() | [any()]}
```

# `status`

```elixir
@type status() :: :registered | :started | :stopped | :restarted | :held
```

# `t`

```elixir
@type t() :: %MishkaInstaller.Event.Event{
  depends: [String.t()],
  event: String.t(),
  extension: atom(),
  extra: [map()],
  id: MishkaDeveloperTools.Helper.UUID.t() | nil,
  inserted_at: DateTime.t() | nil,
  name: module(),
  priority: integer(),
  status: status(),
  updated_at: DateTime.t() | nil
}
```

# `builder`

# `delete`

```elixir
@spec delete(atom(), String.t() | module()) :: error_return() | okey_return()
```

To delete a plugin from Mnesia database by id or name.

> #### Security considerations {: .warning}
>
> It is important to remember that all of the functionalities contained within this
> section must be implemented at the **high access level**, and they should not directly take
> any input from the user. Ensure that you include the required safety measures.

## Example:

```elixir
delete(:name, TestApp.User.Auth)

delete(:id, "c63aea42-209a-40fb-b5c6-a0d28ee7e25b")
```

# `drop`

```elixir
@spec drop() :: {:ok, :atomic} | {:error, any(), charlist()}
```

To drop all plugins from Mnesia database.

> #### Security considerations {: .warning}
>
> It is important to remember that all of the functionalities contained within this
> section must be implemented at the **high access level**, and they should not directly take
> any input from the user. Ensure that you include the required safety measures.

## Example:

```elixir
drop()
```

# `enforce_keys`

# `enforce_keys`

# `get`

```elixir
@spec get() :: [map() | struct()]
```

To get all plugins information from Mnesia database.

> #### Security considerations {: .warning}
>
> It is important to remember that all of the functionalities contained within this
> section must be implemented at the **high access level**, and they should not directly take
> any input from the user. Ensure that you include the required safety measures.

## Example:

```elixir
get()
```

# `get`

```elixir
@spec get(String.t()) :: map() | struct() | nil
```

To get a plugin information from Mnesia database by id.

> #### Security considerations {: .warning}
>
> It is important to remember that all of the functionalities contained within this
> section must be implemented at the **high access level**, and they should not directly take
> any input from the user. Ensure that you include the required safety measures.

## Example:

```elixir
get("c63aea42-209a-40fb-b5c6-a0d28ee7e25b")
```

# `get`

```elixir
@spec get(:name | :event | :extension, module() | String.t()) ::
  [map() | struct()] | map() | struct() | nil
```

To get all plugins or one plugin information from Mnesia database.

> #### Security considerations {: .warning}
>
> It is important to remember that all of the functionalities contained within this
> section must be implemented at the **high access level**, and they should not directly take
> any input from the user. Ensure that you include the required safety measures.

## Example:

```elixir
# All plugins of an event
get(:event, "after_login")

# All plugins of an extension
get(:extension, :mishka_developer_tools)

# Get a plugin
get(:name, TestApp.User.Auth)
```

# `group_events`

```elixir
@spec group_events([atom()]) :: error_return() | okey_return()
```

To get all the events defined in the Mnesia database (Only unique items are returned).

> #### Security considerations {: .warning}
>
> It is important to remember that all of the functionalities contained within this
> section must be implemented at the **high access level**, and they should not directly take
> any input from the user. Ensure that you include the required safety measures.

## Example:

```elixir
group_events()
```

# `ids`

```elixir
@spec ids() :: [String.t()]
```

To get all plugins ids from Mnesia database.

> #### Security considerations {: .warning}
>
> It is important to remember that all of the functionalities contained within this
> section must be implemented at the **high access level**, and they should not directly take
> any input from the user. Ensure that you include the required safety measures.

## Example:

```elixir
ids()
```

# `keys`

# `keys`

# `register`

```elixir
@spec register(module(), String.t(), map()) :: error_return() | okey_return()
```

If you want to store a plugin for a particular event, this function is a predefined strategy
that you can use. Additionally, it performs a check on the integrity of the plugin module and
gathers other information that is necessary while it is being stored in `Mnesia`.

Inputs for this function include the **name of the plugin**, **the name of the event**, and some
**fundamental information**.
Checking the `struct` of this module is one way to add the `initial event` to the modules.

See: `%MishkaInstaller.Event.Event{}`

> #### Security considerations {: .warning}
>
> It is important to remember that all of the functionalities contained within this
> section must be implemented at the **high access level**, and they should not directly take
> any input from the user. Ensure that you include the required safety measures.
>
> This module is a read-only in-memory storage optimized for the fastest possible read times
> not for write strategies.
>
> It is not appropriate for the user to have any direct influence on this function because
> it is intended for the use of the programmer. It should be brought to your attention that
> this particular function, which incorporates the `Write` activity, should often be utilized
> only once at the beginning of the project.

## Example:

```elixir
register(TestApp.User.Auth, "after_login", %{priority: 2})
```

> This function is only responsible for registering the plugin; it does not carry
> out any activities related to execution. Please refer to function `start/2` in order to execute

# `restart`

```elixir
@spec restart(boolean()) :: okey_return() | error_return()
```

This function restarts all events, For more information please see `restart/2`.

# `restart`

```elixir
@spec restart(:name | :event, module() | String.t(), boolean()) ::
  error_return() | okey_return()
```

A pre-made strategy for restarting a plugin is what this method is clearly named.
Keep in mind that you'll need to register and start this plugin ahead of time.

The requested Event will be compiled once more in the event that the
plugin is able to restart properly. **This is a heavy write activity**

> #### Use cases information {: .tip}
>
> The `start/2` function and this idea are often mistaken. Actually, this function does
> the same operations as the start function, but it re-examines the conditions.
> You can tailor your own function to meet the specific needs of your system, and there's
> already a plan in place. The `MishkaInstaller.Event.Hook` module decides on this potential.

---

> #### Security considerations {: .warning}
>
> It is important to remember that all of the functionalities contained within this
> section must be implemented at the **high access level**, and they should not directly take
> any input from the user. Ensure that you include the required safety measures.
>
> This module is a read-only in-memory storage optimized for the fastest possible read times
> not for write strategies.
>
> It is not appropriate for the user to have any direct influence on this function because
> it is intended for the use of the programmer. It should be brought to your attention that
> this particular function, which incorporates the `Write` activity, should often be utilized
> only once at the beginning of the project.

##### Compile path: `MishkaInstaller.Event.ModuleStateCompiler.State.YourEvent`.

## Example:

```elixir
# Restart a plugin
restart(:name, TestApp.User.Auth)

# Restart all plugins of an event
restart(:event, "after_login")
```

# `start`

```elixir
@spec start(boolean()) :: okey_return() | error_return()
```

This function starts all events, For more information please see `start/2`.

# `start`

```elixir
@spec start(:name | :event, module() | String.t(), boolean()) ::
  error_return() | okey_return()
```

A pre-made strategy for starting a plugin is what this method is clearly named.
Keep in mind that you'll need to register this plugin ahead of time.

The requested Event will be compiled once more in the event that the
plugin is able to start properly. **This is a heavy write activity**

> #### Security considerations {: .warning}
>
> It is important to remember that all of the functionalities contained within this
> section must be implemented at the **high access level**, and they should not directly take
> any input from the user. Ensure that you include the required safety measures.
>
> This module is a read-only in-memory storage optimized for the fastest possible read times
> not for write strategies.
>
> It is not appropriate for the user to have any direct influence on this function because
> it is intended for the use of the programmer. It should be brought to your attention that
> this particular function, which incorporates the `Write` activity, should often be utilized
> only once at the beginning of the project.

##### Compile path: `MishkaInstaller.Event.ModuleStateCompiler.State.YourEvent`.

## Example:

```elixir
# Start a plugin
start(:name, TestApp.User.Auth)

# Start all plugins of an event
start(:event, "after_login")
```

# `stop`

```elixir
@spec stop(boolean()) :: okey_return() | error_return()
```

This function stops all events, For more information please see `stop/2`.

# `stop`

```elixir
@spec stop(:name | :event, module() | String.t(), boolean()) ::
  okey_return() | error_return()
```

A pre-made strategy for stopping a plugin is what this method is clearly named.
Keep in mind that you'll need to register and start this plugin ahead of time.

The requested Event will be compiled once more in the event that the
plugin is able to stop properly. **This is a heavy write activity**

> #### Use cases information {: .tip}
>
> Keep in mind that the only thing that happens when you stop a plugin is that its database status
> changes to `stopped` and it is removed from the list of compiled modules
> of the event in question. However, its modules, notably `GenServer`,
> will still be operational and will not be entirely removed from the system.

---

> #### Security considerations {: .warning}
>
> It is important to remember that all of the functionalities contained within this
> section must be implemented at the **high access level**, and they should not directly take
> any input from the user. Ensure that you include the required safety measures.
>
> This module is a read-only in-memory storage optimized for the fastest possible read times
> not for write strategies.
>
> It is not appropriate for the user to have any direct influence on this function because
> it is intended for the use of the programmer. It should be brought to your attention that
> this particular function, which incorporates the `Write` activity, should often be utilized
> only once at the beginning of the project.

## Example:

```elixir
# Stop a plugin
stop(:name, TestApp.User.Auth)

# Stop all plugins of an event
stop(:event, "after_login")
```

# `unique`

To check is a plugin unique or not in Mnesia database.

> It returns `:ok`, or `{:error, reason}`. Note that if the requested plugin does not exist,
> it means it is unique, and if it is already in the database, it means it is not unique

> #### Security considerations {: .warning}
>
> It is important to remember that all of the functionalities contained within this
> section must be implemented at the **high access level**, and they should not directly take
> any input from the user. Ensure that you include the required safety measures.

## Example:

```elixir
unique(:name, TestApp.User.Auth)
```

# `unique?`

This function is exactly like `unique/2` function, except that its output is a Boolean.

> #### Security considerations {: .warning}
>
> It is important to remember that all of the functionalities contained within this
> section must be implemented at the **high access level**, and they should not directly take
> any input from the user. Ensure that you include the required safety measures.

## Example:

```elixir
unique?(:name, TestApp.User.Auth)
```

# `unregister`

```elixir
@spec unregister(boolean()) :: okey_return() | error_return()
```

This function stops all unregisters, For more information please see `unregister/2`.

# `unregister`

```elixir
@spec unregister(:name | :event, module() | String.t(), boolean()) ::
  okey_return() | error_return()
```

This function removes the plugin from the database and **kills** all processes associated to it,
in addition to doing the exact same thing as the `stop/2` function.

The requested Event will be compiled once more in the event that the
plugin is able to unregister properly. **This is a heavy write activity**

> #### Security considerations {: .warning}
>
> It is important to remember that all of the functionalities contained within this
> section must be implemented at the **high access level**, and they should not directly take
> any input from the user. Ensure that you include the required safety measures.
>
> This module is a read-only in-memory storage optimized for the fastest possible read times
> not for write strategies.
>
> It is not appropriate for the user to have any direct influence on this function because
> it is intended for the use of the programmer. It should be brought to your attention that
> this particular function, which incorporates the `Write` activity, should often be utilized
> only once at the beginning of the project.

## Example:

```elixir
# Unregister a plugin
unregister(:name, TestApp.User.Auth)

# Unregister all plugins of an event
unregister(:event, "after_login")
```

# `write`

```elixir
@spec write(builder_entry()) :: error_return() | okey_return()
```

To Add or edit a plugin information from Mnesia database.

> #### Security considerations {: .warning}
>
> It is important to remember that all of the functionalities contained within this
> section must be implemented at the **high access level**, and they should not directly take
> any input from the user. Ensure that you include the required safety measures.

## Example:

```elixir
write(%MishkaInstaller.Event.Event{name: TestApp.User.Auth, event: "after_login", extension: :test_app})
```

# `write`

```elixir
@spec write(atom(), String.t() | module(), map()) :: error_return() | okey_return()
```

To edit a specific field/fields of a plugin from the Mnesia database.

> The first input can only be name and ID `[:id, :name]`.

> #### Security considerations {: .warning}
>
> It is important to remember that all of the functionalities contained within this
> section must be implemented at the **high access level**, and they should not directly take
> any input from the user. Ensure that you include the required safety measures.

## Example:

```elixir
write(:name, TestApp.User.Auth, %{status: :started})
```

---

*Consult [api-reference.md](api-reference.md) for complete listing*
