# Path: hakoblog/config.py
# CONFIG = config()
# 
# Path: hakoblog/loader/user.py
# class UserLoader:
#     @classmethod
#     def find_by_name(cls, db, name):
#         with db.cursor() as cursor:
#             cursor.execute(
#                 """
#                 SELECT id, name
#                 FROM user
#                 WHERE name = %s
#                 LIMIT 1
#                 """,
#                 (name,),
#             )
#             row = cursor.fetchone()
# 
#             if row is None:
#                 return None
# 
#         return User(**row)


from datetime import datetime
from hakoblog.config import CONFIG
from hakoblog.loader.user import UserLoader



class UserAction:
    @classmethod
    def create(self, db, name):
        now = datetime.now()
        new_id = db.uuid_short()
        with db.cursor() as cursor:
            cursor.execute(
                """
                    INSERT INTO user (
                        id, name, created, modified
                    ) VALUES (
                        %s, %s, %s, %s
                    )
                """,
                (new_id, name, now, now),
            )
        return new_id

    @classmethod
    def ensure_global_user_created(cls, db):

# Path: hakoblog/config.py
# CONFIG = config()
# 
# Path: hakoblog/loader/user.py
# class UserLoader:
#     @classmethod
#     def find_by_name(cls, db, name):
#         with db.cursor() as cursor:
#             cursor.execute(
#                 """
#                 SELECT id, name
#                 FROM user
#                 WHERE name = %s
#                 LIMIT 1
#                 """,
#                 (name,),
#             )
#             row = cursor.fetchone()
# 
#             if row is None:
#                 return None
# 
#         return User(**row)


# Path: hakoblog/action/user.py
from datetime import datetime
from hakoblog.config import CONFIG
from hakoblog.loader.user import UserLoader




class UserAction:
    @classmethod
    def create(self, db, name):
        now = datetime.now()
        new_id = db.uuid_short()
        with db.cursor() as cursor:
            cursor.execute(
                """
                    INSERT INTO user (
                        id, name, created, modified
                    ) VALUES (
                        %s, %s, %s, %s
                    )
                """,
                (new_id, name, now, now),
            )
        return new_id

    @classmethod
    def ensure_global_user_created(cls, db):

        global_user_name = CONFIG.GLOBAL_USER_NAME