
from sqlalchemy import Column ,Integer ,String,Boolean,DateTime
from sqlalchemy.orm import Mapped as SQLAlchemyMapped, mapped_column as sqlalchemy_mapped_column
from sqlalchemy.sql import functions as sqlalchemy_functions
import sqlalchemy
from typing import List
from sqlalchemy.orm import relationship
#from app.core.database.models.UserTargetChannel import UserTargetChannel
from app.core.database.table import Base

class User(Base):  # type: ignore
    __tablename__ = "users"
    __table_args__ = {'schema': 'security'}
    id: SQLAlchemyMapped[int] = sqlalchemy_mapped_column(primary_key=True, autoincrement="auto")
    username: SQLAlchemyMapped[str] = sqlalchemy_mapped_column(
        String(length=64), nullable=False, unique=True
    )
    email: SQLAlchemyMapped[str] = sqlalchemy_mapped_column(String(length=64), nullable=False, unique=True)
    hashed_password: SQLAlchemyMapped[str] = sqlalchemy_mapped_column(String(length=1024), nullable=True)
    is_verified: SQLAlchemyMapped[bool] = sqlalchemy_mapped_column(Boolean, nullable=False, default=False)
    is_active: SQLAlchemyMapped[bool] = sqlalchemy_mapped_column(Boolean, nullable=False, default=False)
    is_logged_in: SQLAlchemyMapped[bool] = sqlalchemy_mapped_column(Boolean, nullable=False, default=False)
    created_at: SQLAlchemyMapped[DateTime] = sqlalchemy_mapped_column(
        DateTime(timezone=True), nullable=False, server_default=sqlalchemy_functions.now()
    )
    updated_at: SQLAlchemyMapped[DateTime] = sqlalchemy_mapped_column(
        DateTime(timezone=True),
        nullable=True,
        server_onupdate=sqlalchemy.schema.FetchedValue(for_update=True),
    )
    deleted_at: SQLAlchemyMapped[DateTime] = sqlalchemy_mapped_column(DateTime(timezone=True),nullable=True)
    __mapper_args__ = {"eager_defaults": True}
    
    
    @property
    def hashed_password(self) -> str:
        return self.password

    @hashed_password.setter
    def hashed_password(self, hashed_password: str) -> None:
        self.password = hashed_password
    
    @property
    def hash_salt(self) -> str:
        return self._hash_salt

    def set_hash_salt(self, hash_salt: str) -> None:
        self._hash_salt = hash_salt
