# Model Implementation

## Context

Module: {{MODULE_NAME}}
Model doc: {{MODEL_DOC}}

## Instructions

Implement a database model based on the documentation.

1. Read the model doc at the path above
2. Read existing models in `{{MODULES_ROOT}}/{{MODULE_NAME}}/db/` for patterns
3. Implement the model in `{{MODULES_ROOT}}/{{MODULE_NAME}}/db/<model-name>.ts`

## Implementation Rules

**Read these references before implementing:**

- [Model patterns](models.md) — factory function, generics, stateful enums
- [Database relations](db-relations.md) — `.relation()` for foreign keys
- [Cross-module dependencies](cross-module-dependency.md) — DB type injection

### Key Patterns

1. **Factory function**: `export function create<Model>Type<const F extends Record<string, TailorAnyDBField> = Record<string, never>>(params?: { customFields?: F })`
2. **Timestamps**: Always include `db.fields.timestamps()`
3. **Descriptions**: Add `.description()` on every field
4. **Relations**: Use `.relation()` instead of plain `db.uuid()` for foreign keys
5. **Stateful models**: Use `additionalStatuses` for extension, never replace base statuses

### From Doc to Code

| Doc Element        | Code Element                              |
| ------------------ | ----------------------------------------- |
| Fields table       | `db.fields.*` definitions                 |
| Required fields    | Field without `.optional()`               |
| Status/state enum  | `db.fields.enum()` with status values     |
| Relationships      | `.relation()` with type and toward config |
| Unique constraints | `.unique()` on fields or composite index  |

## Output

Write the model file to `{{MODULES_ROOT}}/{{MODULE_NAME}}/db/<model-name>.ts`.
Follow existing patterns in the module's `db/` directory.
