from peewee import SqliteDatabase

from persistence import article_models, message_models

# Global logger setup:


# Constant values...
DOWNLOADS_DB = "../container_data/downloads.db"
MESSAGES_DB = "../container_data/messages.db"

BOT_ID = "U02MR1R8UJH"
ARCHIVE_ID = "C02MM7YG1V4"
DEBUG_ID = "C02NM2H9J5Q"


# DB Setup:
article_models.set_db(SqliteDatabase(
    DOWNLOADS_DB,
    pragmas = {'journal_mode': 'wal'} # mutliple threads can access at once
))

message_models.set_db(SqliteDatabase(MESSAGES_DB))



for reaction in message_models.Reaction.select():
    print(reaction)        
    thread = reaction.message.thread
    articles = message_models.get_referenced_articles(thread, article_models.ArticleDownload)
    for a in articles:
        print(a)
    reaction = reaction.type
    status = 1 if reaction == "white_check_mark" else -1
    print(status)
    for article in articles:
        article.verified = status
        article.save()
