"""Seed demo data for local smoke testing."""

from gnexus_creds.db import SessionLocal
from gnexus_creds.schemas import SecretCreate, SecretFieldIn
from gnexus_creds.services import Actor, create_secret, upsert_user_from_auth


def main() -> None:
    with SessionLocal() as db:
        user = upsert_user_from_auth(
            db,
            auth_subject="demo-user",
            email="demo@example.test",
            display_name="Demo User",
            profile={"locale": "en"},
            system_role="admin",
        )
        actor = Actor(user=user, channel="ui")
        create_secret(
            db,
            actor,
            SecretCreate(
                title="Demo SSH server",
                purpose="demo.internal",
                category="infra",
                source="manual seed",
                tags=["ssh", "demo"],
                allow_mcp=True,
                fields=[
                    SecretFieldIn(name="host", value="demo.internal", encrypted=False, position=1),
                    SecretFieldIn(name="username", value="deploy", encrypted=False, position=2),
                    SecretFieldIn(
                        name="private_key",
                        value="-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----",
                        encrypted=True,
                        masked=True,
                        position=3,
                    ),
                ],
            ),
        )
        db.commit()
    print("Seeded demo user and secrets.")


if __name__ == "__main__":
    main()
