from __future__ import annotations

from app import db


class User(db.Model):
    __tablename__ = "users"

    id = db.Column(db.Uuid(as_uuid=False), primary_key=True)
    username = db.Column(db.String(64), unique=True, nullable=False)
    display_name = db.Column(db.String(100))
    password_hash = db.Column(db.Text, nullable=False)
    status = db.Column(db.String(20), nullable=False, default="active")
    created_at = db.Column(db.DateTime(timezone=True), nullable=False)
    updated_at = db.Column(db.DateTime(timezone=True), nullable=False)
    last_login_at = db.Column(db.DateTime(timezone=True))


class Role(db.Model):
    __tablename__ = "roles"

    id = db.Column(db.Uuid(as_uuid=False), primary_key=True)
    name = db.Column(db.String(32), unique=True, nullable=False)
    description = db.Column(db.String(200), nullable=False)


class UserRole(db.Model):
    __tablename__ = "user_roles"

    user_id = db.Column(db.Uuid(as_uuid=False), primary_key=True)
    role_id = db.Column(db.Uuid(as_uuid=False), primary_key=True)


class AuthAuditEvent(db.Model):
    __tablename__ = "auth_audit_events"

    id = db.Column(db.BigInteger, primary_key=True)
    user_id = db.Column(db.Uuid(as_uuid=False))
    username = db.Column(db.String(64))
    event_type = db.Column(db.String(40), nullable=False)
    success = db.Column(db.Boolean, nullable=False)
