from datetime import datetime
from flask_sqlalchemy import SQLAlchemy

db = SQLAlchemy()


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

    id = db.Column(db.Integer, primary_key=True)

    name = db.Column(db.String(120), nullable=False)
    email = db.Column(db.String(160), unique=True, nullable=False, index=True)

    role = db.Column(db.String(50), default="app")  # app | admin
    active = db.Column(db.Boolean, default=True)

    password_hash = db.Column(db.String(255))
    must_change_password = db.Column(db.Boolean, default=True)

    reset_token = db.Column(db.String(255))
    reset_expire = db.Column(db.DateTime)

    created_at = db.Column(db.DateTime, default=datetime.utcnow)

    def __repr__(self):
        return f"<User {self.email}>"