# `MishkaGervaz.Table.Web.Events.RecordHandler`
[🔗](https://github.com/mishka-group/mishka_gervaz/blob/v0.0.1-alpha.3/lib/mishka_gervaz/table/web/events/record_handler.ex#L1)

Handles record operations for Events module.

This module provides functions for fetching, deleting, unarchiving, and
permanently destroying records.

## Customization

You can create a custom RecordHandler:

    defmodule MyApp.CustomRecordHandler do
      use MishkaGervaz.Table.Web.Events.RecordHandler

      # Custom delete that adds audit logging
      def delete_record(state, record) do
        result = super(state, record)
        MyApp.AuditLog.log_delete(record, state.current_user)
        result
      end
    end

Then configure it in your resource's DSL:

    mishka_gervaz do
      table do
        events do
          record MyApp.CustomRecordHandler
        end
      end
    end

See `MishkaGervaz.Table.Web.Events`,
`MishkaGervaz.Table.Web.DataLoader`,
and the sibling handlers `SanitizationHandler`, `SelectionHandler`,
`BulkActionHandler`, `HookRunner`, `RelationFilterHandler`.

# `archive_status`

```elixir
@type archive_status() :: :active | :archived
```

# `record`

```elixir
@type record() :: struct()
```

# `state`

```elixir
@type state() :: MishkaGervaz.Table.Web.State.t()
```

# `delete_record`

```elixir
@callback delete_record(state :: state(), record :: record()) ::
  {:ok, record()} | {:error, term()}
```

Deletes a record using the source destroy action.

Returns `{:ok, deleted_record}` or `{:error, reason}`.

# `destroy_record`

```elixir
@callback destroy_record(
  state :: state(),
  record :: record(),
  action :: atom() | {atom(), atom()}
) :: {:ok, record()} | {:error, term()}
```

Destroys a record with a specific Ash action.

The action can be an atom or tuple {master_action, tenant_action}.
Returns `{:ok, destroyed_record}` or `{:error, reason}`.

# `get_record`

```elixir
@callback get_record(
  state :: state(),
  id :: String.t(),
  archive_status :: archive_status()
) :: record()
```

Fetches a record by ID.

Uses the appropriate action based on archive status and user type.

# `permanent_destroy_record`

```elixir
@callback permanent_destroy_record(state :: state(), record :: record()) ::
  {:ok, record()} | {:error, term()}
```

Permanently destroys an archived record.

Returns `{:ok, destroyed_record}` or `{:error, reason}`.

# `unarchive_record`

```elixir
@callback unarchive_record(state :: state(), record :: record()) ::
  {:ok, record()} | {:error, term()}
```

Restores an archived record.

Returns `{:ok, restored_record}` or `{:error, reason}`.

# `update_record`

```elixir
@callback update_record(
  state :: state(),
  record :: record(),
  action :: atom() | {atom(), atom()}
) :: {:ok, record()} | {:error, term()}
```

Updates a record with a specific Ash action.

The action can be an atom or tuple {master_action, tenant_action}.
Returns `{:ok, updated_record}` or `{:error, reason}`.

---

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