from sqlmodel import select
from sqlalchemy.sql import expression
from sqlalchemy.exc import SQLAlchemyError
from sqlalchemy.orm import defer
from typing import Any
from app.db import models, pagination, session_scope
from app.logs import fastapi_logger


def get_user(email: str) -> Any:
    """ Get User Data based on email"""
    try:
        with session_scope() as db:
            statement = select(models.User).where(
                models.User.email == email).options(defer('password'))
            results = db.exec(statement)
            data = results.one()
            return data
    except SQLAlchemyError as e:
        fastapi_logger.exception("get_user")
        return None

def get_user_password(email: str) -> Any:
    """ Get User Password based on email"""
    try:
        with session_scope() as db:
            statement = select(models.User).where(
                models.User.email == email)
            results = db.exec(statement)
            data = results.one()
            return data
    except SQLAlchemyError as e:
        fastapi_logger.exception("get_user")
        return None

def get_active_user(email: str) -> Any:
    """ Get User Data based on email and active status"""
    try:
        with session_scope() as db:
            statement = select(models.User).where(
                models.User.email == email).where(
                models.User.is_active == expression.true()).options(defer('password'))
            results = db.exec(statement)
            data = results.one()
            return data
    except SQLAlchemyError as e:
        fastapi_logger.exception("get_user")
        return None

sqlalchemy.sql.expression.true app.db.session_scope app.logs.fastapi_logger.exception sqlalchemy.orm.defer sqlmodel.select
[((363, 378), 'app.db.session_scope', 'session_scope', ([], {}), '()\n', (376, 378), False, 'from app.db import models, pagination, session_scope\n'), ((654, 690), 'app.logs.fastapi_logger.exception', 'fastapi_logger.exception', (['"""get_user"""'], {}), "('get_user')\n", (678, 690), False, 'from app.logs import fastapi_logger\n'), ((826, 841), 'app.db.session_scope', 'session_scope', ([], {}), '()\n', (839, 841), False, 'from app.db import models, pagination, session_scope\n'), ((1090, 1126), 'app.logs.fastapi_logger.exception', 'fastapi_logger.exception', (['"""get_user"""'], {}), "('get_user')\n", (1114, 1126), False, 'from app.logs import fastapi_logger\n'), ((1274, 1289), 'app.db.session_scope', 'session_scope', ([], {}), '()\n', (1287, 1289), False, 'from app.db import models, pagination, session_scope\n'), ((1633, 1669), 'app.logs.fastapi_logger.exception', 'fastapi_logger.exception', (['"""get_user"""'], {}), "('get_user')\n", (1657, 1669), False, 'from app.logs import fastapi_logger\n'), ((491, 508), 'sqlalchemy.orm.defer', 'defer', (['"""password"""'], {}), "('password')\n", (496, 508), False, 'from sqlalchemy.orm import defer\n'), ((1470, 1487), 'sqlalchemy.orm.defer', 'defer', (['"""password"""'], {}), "('password')\n", (1475, 1487), False, 'from sqlalchemy.orm import defer\n'), ((874, 893), 'sqlmodel.select', 'select', (['models.User'], {}), '(models.User)\n', (880, 893), False, 'from sqlmodel import select\n'), ((411, 430), 'sqlmodel.select', 'select', (['models.User'], {}), '(models.User)\n', (417, 430), False, 'from sqlmodel import select\n'), ((1443, 1460), 'sqlalchemy.sql.expression.true', 'expression.true', ([], {}), '()\n', (1458, 1460), False, 'from sqlalchemy.sql import expression\n'), ((1322, 1341), 'sqlmodel.select', 'select', (['models.User'], {}), '(models.User)\n', (1328, 1341), False, 'from sqlmodel import select\n')]