# API

**Assembly:** `Spark.Classes` **Interface:** `IClassesPlugin` **Implementation:** `ClassesPlugin`

## Interface

```csharp
public interface IClassesPlugin
{
    // Database queries
    List<ClassEntry> GetAllClasses();
    ClassEntry GetClass(string classId);

    // Main class
    void SetMainClass(string entityId, string classId,
        GameObject source = null);
    string GetMainClass(string entityId);

    // Secondary classes
    void AddSecondaryClass(string entityId, string classId,
        GameObject source = null);
    void RemoveSecondaryClass(string entityId, string classId);
    List<string> GetSecondaryClasses(string entityId);

    // Unlocking
    void UnlockClass(string entityId, string classId,
        GameObject source = null);
    bool IsClassUnlocked(string entityId, string classId);
    List<string> GetUnlockedClasses(string entityId);
}
```

## ClassEntry

Extends `SparkDatabaseEntry`. Defines a character class (Warrior, Mage, etc.).

The entry is intentionally minimal. Class depth comes from extensions added by other plugins (Combat stats, Progression, Spellbooks, etc.).

## Events

| Event                | Fields                                 | Description    |
| -------------------- | -------------------------------------- | -------------- |
| `ClassSelectedEvent` | EntityId, ClassId, IsMainClass, Source | Class assigned |
| `ClassUnlockedEvent` | EntityId, ClassId, Source              | Class unlocked |

Both events are struct-based `ISparkEvent` implementations with a `Timestamp` field.

## Save Data

### ClassesSaveData

Extends `SaveDataEntry`.

| Field               | Type          | Description                   |
| ------------------- | ------------- | ----------------------------- |
| `mainClassId`       | string        | Currently selected main class |
| `secondaryClassIds` | List\<string> | Active secondary classes      |
| `unlockedClassIds`  | List\<string> | All unlocked classes          |

**Methods:**

```csharp
void SetMainClass(string classId)
string GetMainClass()
void AddSecondaryClass(string classId)
void RemoveSecondaryClass(string classId)
void UnlockClass(string classId)
List<string> GetSecondaryClasses()
List<string> GetAllUnlockedClasses()
bool IsClassUnlocked(string classId)
```

Setting a main or secondary class automatically unlocks it.

## Usage

```csharp
var classes = Spark.GetPlugin<IClassesPlugin>();
if (classes != null)
{
    // Set the player's main class
    classes.SetMainClass(entityId, "warrior");

    // Add a secondary class
    classes.AddSecondaryClass(entityId, "mage");

    // Unlock a class without assigning it
    classes.UnlockClass(entityId, "ranger");

    // Query class state
    string main = classes.GetMainClass(entityId);
    var secondary = classes.GetSecondaryClasses(entityId);
    bool hasMage = classes.IsClassUnlocked(entityId, "mage");
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.sparkframework.dev/documentation/developer-guide/plugins/classes/api.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
