# Path: jarr/lib/utils.py
# def utc_now():
#     return datetime.utcnow().replace(tzinfo=timezone.utc)
# 
# Path: jarr/bootstrap.py
# def is_secure_served():
# def init_logging(log_path=None, log_level=logging.INFO, modules=(),
#                  log_format='%(asctime)s %(levelname)s %(message)s'):
# def init_db(echo=False):
# def init_models():
# def commit_pending_sql(*args, **kwargs):
# def rollback_pending_sql(*args, **kwargs):
# REDIS_CONN = Redis(host=conf.db.redis.host,
#                    db=conf.db.redis.db,
#                    port=conf.db.redis.port)
# 
# Path: jarr/models/utc_datetime_type.py
# class UTCDateTime(types.TypeDecorator):
#     impl = types.DateTime
#     python_type = datetime
#     cache_ok = True
# 
#     @staticmethod
#     def process_bind_param(value, dialect):
#         if value is not None:
#             if not value.tzinfo:
#                 value = value.replace(tzinfo=timezone.utc)
#             return value.astimezone(timezone.utc).replace(tzinfo=None)
#         return value
# 
#     @staticmethod
#     def process_result_value(value, dialect):
#         if value is not None:
#             if value.tzinfo:
#                 raise ValueError(f"{value!r} tzinfo is defined, shouldn't be")
#             return value.replace(tzinfo=timezone.utc)
#         return value
# 
#     @staticmethod
#     def process_literal_param(value, dialect):
#         raise NotImplementedError(f"can't process {value!r} for {dialect!r}")


import re
from datetime import timedelta
from sqlalchemy import Boolean, Column, Integer, String, PickleType
from sqlalchemy.orm import relationship, validates, RelationshipProperty
from jarr.lib.utils import utc_now
from jarr.bootstrap import Base, conf
from jarr.models.utc_datetime_type import UTCDateTime

class User(Base):  # type: ignore
    __tablename__ = 'user'

    id = Column(Integer, primary_key=True)
    login = Column(String, unique=True)
    password = Column(String)
    email = Column(String(254))
    date_created = Column(UTCDateTime, default=utc_now)
    last_connection = Column(UTCDateTime, default=utc_now)
    renew_password_token = Column(String, default='')

    timezone = Column(String, default=conf.timezone)

    # clustering control
    cluster_enabled = Column(Boolean, default=True, nullable=False)
    cluster_tfidf_enabled = Column(Boolean, default=True, nullable=False)
    cluster_same_category = Column(Boolean, default=True, nullable=False)
    cluster_same_feed = Column(Boolean, default=True, nullable=False)
    cluster_wake_up = Column(Boolean, default=True, nullable=False)
    cluster_conf = Column(PickleType, default={})

    # user rights
    is_active = Column(Boolean, default=True)
    is_admin = Column(Boolean, default=False)
    is_api = Column(Boolean, default=False)

    # oauth identites
    google_identity = Column(String)
    twitter_identity = Column(String)

# Path: jarr/lib/utils.py
# def utc_now():
#     return datetime.utcnow().replace(tzinfo=timezone.utc)
# 
# Path: jarr/bootstrap.py
# def is_secure_served():
# def init_logging(log_path=None, log_level=logging.INFO, modules=(),
#                  log_format='%(asctime)s %(levelname)s %(message)s'):
# def init_db(echo=False):
# def init_models():
# def commit_pending_sql(*args, **kwargs):
# def rollback_pending_sql(*args, **kwargs):
# REDIS_CONN = Redis(host=conf.db.redis.host,
#                    db=conf.db.redis.db,
#                    port=conf.db.redis.port)
# 
# Path: jarr/models/utc_datetime_type.py
# class UTCDateTime(types.TypeDecorator):
#     impl = types.DateTime
#     python_type = datetime
#     cache_ok = True
# 
#     @staticmethod
#     def process_bind_param(value, dialect):
#         if value is not None:
#             if not value.tzinfo:
#                 value = value.replace(tzinfo=timezone.utc)
#             return value.astimezone(timezone.utc).replace(tzinfo=None)
#         return value
# 
#     @staticmethod
#     def process_result_value(value, dialect):
#         if value is not None:
#             if value.tzinfo:
#                 raise ValueError(f"{value!r} tzinfo is defined, shouldn't be")
#             return value.replace(tzinfo=timezone.utc)
#         return value
# 
#     @staticmethod
#     def process_literal_param(value, dialect):
#         raise NotImplementedError(f"can't process {value!r} for {dialect!r}")


# Path: jarr/models/user.py
import re
from datetime import timedelta
from sqlalchemy import Boolean, Column, Integer, String, PickleType
from sqlalchemy.orm import relationship, validates, RelationshipProperty
from jarr.lib.utils import utc_now
from jarr.bootstrap import Base, conf
from jarr.models.utc_datetime_type import UTCDateTime


class User(Base):  # type: ignore
    __tablename__ = 'user'

    id = Column(Integer, primary_key=True)
    login = Column(String, unique=True)
    password = Column(String)
    email = Column(String(254))
    date_created = Column(UTCDateTime, default=utc_now)
    last_connection = Column(UTCDateTime, default=utc_now)
    renew_password_token = Column(String, default='')

    timezone = Column(String, default=conf.timezone)

    # clustering control
    cluster_enabled = Column(Boolean, default=True, nullable=False)
    cluster_tfidf_enabled = Column(Boolean, default=True, nullable=False)
    cluster_same_category = Column(Boolean, default=True, nullable=False)
    cluster_same_feed = Column(Boolean, default=True, nullable=False)
    cluster_wake_up = Column(Boolean, default=True, nullable=False)
    cluster_conf = Column(PickleType, default={})

    # user rights
    is_active = Column(Boolean, default=True)
    is_admin = Column(Boolean, default=False)
    is_api = Column(Boolean, default=False)

    # oauth identites
    google_identity = Column(String)
    twitter_identity = Column(String)

    facebook_identity = Column(String)