"""Prism specification for {{ project_name }}.

Starter spec — edit these models and run `prisme generate` to create the full stack.
"""

from prisme import (
    FieldSpec,
    FieldType,
    FilterOperator,
    ModelSpec,
    RelationshipSpec,
    StackSpec,
)

spec = StackSpec(
    name="{{ project_name_snake }}",
    version="1.0.0",
    description="{{ description }}",
    models=[
        ModelSpec(
            name="Plan",
            description="A subscription plan with pricing and features",
            fields=[
                FieldSpec(
                    name="name",
                    type=FieldType.STRING,
                    max_length=100,
                    required=True,
                    searchable=True,
                    filter_operators=[FilterOperator.EQ, FilterOperator.CONTAINS],
                ),
                FieldSpec(
                    name="description",
                    type=FieldType.TEXT,
                ),
                FieldSpec(
                    name="price_monthly",
                    type=FieldType.DECIMAL,
                    precision=10,
                    scale=2,
                    required=True,
                ),
                FieldSpec(
                    name="features",
                    type=FieldType.JSON,
                ),
                FieldSpec(
                    name="is_active",
                    type=FieldType.BOOLEAN,
                    default=True,
                ),
            ],
            relationships=[
                RelationshipSpec(
                    name="subscriptions",
                    target_model="Subscription",
                    type="one_to_many",
                    back_populates="plan",
                ),
            ],
            timestamps=True,
        ),
        ModelSpec(
            name="Subscription",
            description="A tenant's subscription to a plan",
            fields=[
                FieldSpec(
                    name="status",
                    type=FieldType.ENUM,
                    enum_values=["trial", "active", "past_due", "cancelled"],
                    default="trial",
                ),
                FieldSpec(
                    name="started_at",
                    type=FieldType.DATETIME,
                    required=True,
                ),
                FieldSpec(
                    name="expires_at",
                    type=FieldType.DATETIME,
                ),
                FieldSpec(
                    name="plan_id",
                    type=FieldType.FOREIGN_KEY,
                    references="Plan",
                    required=True,
                ),
                FieldSpec(
                    name="tenant_id",
                    type=FieldType.FOREIGN_KEY,
                    references="Tenant",
                    required=True,
                ),
            ],
            relationships=[
                RelationshipSpec(
                    name="plan",
                    target_model="Plan",
                    type="many_to_one",
                    back_populates="subscriptions",
                ),
                RelationshipSpec(
                    name="tenant",
                    target_model="Tenant",
                    type="many_to_one",
                    back_populates="subscriptions",
                ),
            ],
            timestamps=True,
            soft_delete=True,
        ),
        ModelSpec(
            name="Tenant",
            description="A tenant (organization) in the multi-tenant system",
            fields=[
                FieldSpec(
                    name="name",
                    type=FieldType.STRING,
                    max_length=255,
                    required=True,
                    searchable=True,
                    filter_operators=[FilterOperator.EQ, FilterOperator.CONTAINS],
                ),
                FieldSpec(
                    name="slug",
                    type=FieldType.STRING,
                    max_length=100,
                    unique=True,
                    required=True,
                ),
                FieldSpec(
                    name="is_active",
                    type=FieldType.BOOLEAN,
                    default=True,
                ),
            ],
            relationships=[
                RelationshipSpec(
                    name="users",
                    target_model="User",
                    type="one_to_many",
                    back_populates="tenant",
                ),
                RelationshipSpec(
                    name="subscriptions",
                    target_model="Subscription",
                    type="one_to_many",
                    back_populates="tenant",
                ),
            ],
            timestamps=True,
            soft_delete=True,
        ),
        ModelSpec(
            name="User",
            description="A user belonging to a tenant",
            fields=[
                FieldSpec(
                    name="email",
                    type=FieldType.STRING,
                    max_length=255,
                    unique=True,
                    required=True,
                    searchable=True,
                    filter_operators=[FilterOperator.EQ, FilterOperator.CONTAINS],
                ),
                FieldSpec(
                    name="display_name",
                    type=FieldType.STRING,
                    max_length=255,
                    required=True,
                ),
                FieldSpec(
                    name="role",
                    type=FieldType.ENUM,
                    enum_values=["owner", "admin", "member", "viewer"],
                    default="member",
                ),
                FieldSpec(
                    name="is_active",
                    type=FieldType.BOOLEAN,
                    default=True,
                ),
                FieldSpec(
                    name="tenant_id",
                    type=FieldType.FOREIGN_KEY,
                    references="Tenant",
                    required=True,
                ),
            ],
            relationships=[
                RelationshipSpec(
                    name="tenant",
                    target_model="Tenant",
                    type="many_to_one",
                    back_populates="users",
                ),
            ],
            timestamps=True,
            soft_delete=True,
        ),
    ],
)
