import os

from dotenv import load_dotenv


from .base import *  # isort:skip


load_dotenv()

DEBUG = False

ALLOWED_HOSTS = ["rss.fudiggity.nl"]
ADMINS = [
    ("", email)
    for email in os.getenv("ADMINS", "").split(",")
    if os.environ.get("ADMINS")
]

SECRET_KEY = os.environ["DJANGO_SECRET_KEY"]

DATABASES = {
    "default": {
        "ENGINE": "django.db.backends.postgresql",
        "HOST": os.environ["POSTGRES_HOST"],
        "PORT": os.environ["POSTGRES_PORT"],
        "NAME": os.environ["POSTGRES_NAME"],
        "USER": os.environ["POSTGRES_USER"],
        "PASSWORD": os.environ["POSTGRES_PASSWORD"],
    }
}

TEMPLATES = [
    {
        "BACKEND": "django.template.backends.django.DjangoTemplates",
        "DIRS": [os.path.join(DJANGO_PROJECT_DIR, "templates")],
        "APP_DIRS": True,
        "OPTIONS": {
            "context_processors": [
                "django.template.context_processors.request",
                "django.contrib.auth.context_processors.auth",
                "django.contrib.messages.context_processors.messages",
            ]
        },
    }
]

# Reddit integration
REDDIT_CLIENT_ID = os.environ.get("REDDIT_CLIENT_ID", "")
REDDIT_CLIENT_SECRET = os.environ.get("REDDIT_CLIENT_SECRET", "")
REDDIT_REDIRECT_URL = os.environ.get("REDDIT_CALLBACK_URL", "")

# Twitter integration
TWITTER_CONSUMER_ID = os.environ.get("TWITTER_CONSUMER_ID", "")
TWITTER_CONSUMER_SECRET = os.environ.get("TWITTER_CONSUMER_SECRET", "")
TWITTER_REDIRECT_URL = os.environ.get("TWITTER_REDIRECT_URL", "")

# Third party settings
AXES_HANDLER = "axes.handlers.database.AxesDatabaseHandler"

REGISTRATION_OPEN = False

# Optionally use sentry integration
try:
    from sentry_sdk import init as sentry_init
    from sentry_sdk.integrations.celery import CeleryIntegration
    from sentry_sdk.integrations.django import DjangoIntegration

    sentry_init(
        dsn=os.environ.get("SENTRY_DSN"),
        integrations=[DjangoIntegration(), CeleryIntegration()],
        send_default_pii=False,
        release=VERSION,
    )
except ImportError:
    pass
