# Path: code/common/database/detailed_item.py
# class DetailedItem(CommandItem):
#     def __init__(self, discord_context, query, command, is_valid):
#         self.discord_context = discord_context
#         author = self.discord_context.message.author
#         channel = self.discord_context.message.channel
#         guild = self.discord_context.message.guild
# 
#         self.user_id = int(author.id)
#         self.user_name = "{}#{}".format(author.name, author.discriminator)
#         self.timestamp = int(self.discord_context.message.created_at.timestamp() * 1000)    # float to milliseconds timestamp
#         self.channel_id = channel.id
#         self.channel_name = channel.name
#         self.server_id = guild.id
#         self.server_name = guild.name
# 
#         self.query = query
#         self.command = command
#         self.is_valid = is_valid
#         ## Milliseconds timestamp to seconds, as AWS TTL only works in seconds increments. Defaults to a year from the timestamp
#         self.expires_on = (self.timestamp / 1000) + CONFIG_OPTIONS.get("database_detailed_table_ttl_seconds", 31536000)
# 
#         self.primary_key_name = CONFIG_OPTIONS.get("boto_primary_key", "QueryId")
#         self.primary_key = self.build_primary_key()
# 
#     ## Methods
# 
#     def to_json(self) -> Dict:
#         return {
#             'user_id': int(self.user_id),
#             'user_name': str(self.user_name),
#             'timestamp': int(self.timestamp),
#             'channel_id': int(self.channel_id),
#             'channel_name': str(self.channel_name),
#             'server_id': int(self.server_id),
#             'server_name': str(self.server_name),
#             'query': str(self.query),
#             'command': str(self.command),
#             'is_valid': bool(self.is_valid),
#             'expires_on': int(self.expires_on),
#             self.primary_key_name: str(self.primary_key),
#         }
# 
# 
#     def build_primary_key(self) -> str:
#         concatenated = "{}{}".format(self.user_id, self.timestamp)
# 
#         return base64.b64encode(bytes(concatenated, "utf-8")).decode("utf-8")
# 
# 
#     def to_anonymous_item(self) -> AnonymousItem:
#         return AnonymousItem(self.discord_context, self.command, self.query, self.is_valid)


import os
import logging
import inspect
import boto3
from boto3.dynamodb.conditions import Key
from common import utilities
from .detailed_item import DetailedItem
        self.credentials_path = CONFIG_OPTIONS.get('database_credentials_file_path')
        self.resource = CONFIG_OPTIONS.get('database_resource', 'dynamodb')
        self.region_name = CONFIG_OPTIONS.get('database_region_name', 'us-east-2')
        self.detailed_table_name = CONFIG_OPTIONS.get('database_detailed_table_name', 'HawkingDetailed')
        self.anonymous_table_name = CONFIG_OPTIONS.get('database_anonymous_table_name', 'HawkingAnonymous')
        self.primary_key = CONFIG_OPTIONS.get('database_primary_key', 'QueryId')
        self.detailed_table_ttl_seconds = CONFIG_OPTIONS.get('database_detailed_table_ttl_seconds', 31536000)

        self.dynamo_db = boto3.resource(self.resource, region_name=self.region_name)
        self.detailed_table = self.dynamo_db.Table(self.detailed_table_name)
        self.anonymous_table = self.dynamo_db.Table(self.anonymous_table_name)

    ## Properties

    @property
    def credentials_path(self):
        return self._credentials_path


    @credentials_path.setter
    def credentials_path(self, value):
        if (not value):
            self._credentials_path = None
            return

        self._credentials_path = value
        os.environ['AWS_SHARED_CREDENTIALS_FILE'] = self.credentials_path

    ## Methods


# Path: code/common/database/detailed_item.py
# class DetailedItem(CommandItem):
#     def __init__(self, discord_context, query, command, is_valid):
#         self.discord_context = discord_context
#         author = self.discord_context.message.author
#         channel = self.discord_context.message.channel
#         guild = self.discord_context.message.guild
# 
#         self.user_id = int(author.id)
#         self.user_name = "{}#{}".format(author.name, author.discriminator)
#         self.timestamp = int(self.discord_context.message.created_at.timestamp() * 1000)    # float to milliseconds timestamp
#         self.channel_id = channel.id
#         self.channel_name = channel.name
#         self.server_id = guild.id
#         self.server_name = guild.name
# 
#         self.query = query
#         self.command = command
#         self.is_valid = is_valid
#         ## Milliseconds timestamp to seconds, as AWS TTL only works in seconds increments. Defaults to a year from the timestamp
#         self.expires_on = (self.timestamp / 1000) + CONFIG_OPTIONS.get("database_detailed_table_ttl_seconds", 31536000)
# 
#         self.primary_key_name = CONFIG_OPTIONS.get("boto_primary_key", "QueryId")
#         self.primary_key = self.build_primary_key()
# 
#     ## Methods
# 
#     def to_json(self) -> Dict:
#         return {
#             'user_id': int(self.user_id),
#             'user_name': str(self.user_name),
#             'timestamp': int(self.timestamp),
#             'channel_id': int(self.channel_id),
#             'channel_name': str(self.channel_name),
#             'server_id': int(self.server_id),
#             'server_name': str(self.server_name),
#             'query': str(self.query),
#             'command': str(self.command),
#             'is_valid': bool(self.is_valid),
#             'expires_on': int(self.expires_on),
#             self.primary_key_name: str(self.primary_key),
#         }
# 
# 
#     def build_primary_key(self) -> str:
#         concatenated = "{}{}".format(self.user_id, self.timestamp)
# 
#         return base64.b64encode(bytes(concatenated, "utf-8")).decode("utf-8")
# 
# 
#     def to_anonymous_item(self) -> AnonymousItem:
#         return AnonymousItem(self.discord_context, self.command, self.query, self.is_valid)


# Path: code/common/database/dynamo_manager.py
import os
import logging
import inspect
import boto3
from boto3.dynamodb.conditions import Key
from common import utilities
from .detailed_item import DetailedItem

        self.credentials_path = CONFIG_OPTIONS.get('database_credentials_file_path')
        self.resource = CONFIG_OPTIONS.get('database_resource', 'dynamodb')
        self.region_name = CONFIG_OPTIONS.get('database_region_name', 'us-east-2')
        self.detailed_table_name = CONFIG_OPTIONS.get('database_detailed_table_name', 'HawkingDetailed')
        self.anonymous_table_name = CONFIG_OPTIONS.get('database_anonymous_table_name', 'HawkingAnonymous')
        self.primary_key = CONFIG_OPTIONS.get('database_primary_key', 'QueryId')
        self.detailed_table_ttl_seconds = CONFIG_OPTIONS.get('database_detailed_table_ttl_seconds', 31536000)

        self.dynamo_db = boto3.resource(self.resource, region_name=self.region_name)
        self.detailed_table = self.dynamo_db.Table(self.detailed_table_name)
        self.anonymous_table = self.dynamo_db.Table(self.anonymous_table_name)

    ## Properties

    @property
    def credentials_path(self):
        return self._credentials_path


    @credentials_path.setter
    def credentials_path(self, value):
        if (not value):
            self._credentials_path = None
            return

        self._credentials_path = value
        os.environ['AWS_SHARED_CREDENTIALS_FILE'] = self.credentials_path

    ## Methods


    def put(self, dynamo_item: DetailedItem):