import os
import sentry_sdk
from sentry_sdk.integrations.django import DjangoIntegration

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

PWA_SERVICE_WORKER_PATH = os.path.join(
    BASE_DIR, 'routes/static/routes/js', 'serviceworker.js')
print(os.path.join(
    BASE_DIR, 'routes/static/routes/js', 'serviceworker.js'))

DEBUG = int(os.environ.get("DEBUG", default=0))

SECRET_KEY = os.environ.get("SECRET_KEY", 'asdfkhbsadgui87gjsbdfui')

# 'DJANGO_ALLOWED_HOSTS' should be a single string of hosts with a space between each.
# For example: 'DJANGO_ALLOWED_HOSTS=localhost 127.0.0.1 [::1]'
ALLOWED_HOSTS = os.environ.get("DJANGO_ALLOWED_HOSTS", 'localhost').split(" ")

# Application definition

INSTALLED_APPS = [
    'routes',
    'accounts',
    'dashboard.apps.DashboardConfig',
    'api.apps.ApiConfig',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'widget_tweaks',
    'rest_framework',
    'pwa',
]
# 'celery',


MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'tracks.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'tracks.wsgi.application'


# Database
# https://docs.djangoproject.com/en/2.2/ref/settings/#databases

DATABASES = {
    "default": {
        "ENGINE": os.environ.get("SQL_ENGINE", "django.db.backends.sqlite3"),
        "NAME": os.environ.get("SQL_DATABASE", os.path.join(BASE_DIR, "db.sqlite3")),
        "USER": os.environ.get("SQL_USER", "user"),
        "PASSWORD": os.environ.get("SQL_PASSWORD", "password"),
        "HOST": os.environ.get("SQL_HOST", "localhost"),
        "PORT": os.environ.get("SQL_PORT", "5432"),
    }
}

# Password validation
# https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/2.2/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.2/howto/static-files/

STATIC_URL = '/static/'
MEDIA_URL = '/media/'

STATIC_ROOT = './static/'
MEDIA_ROOT = './media/'

LOGIN_REDIRECT_URL = 'home'
LOGOUT_REDIRECT_URL = 'home'

# no email for localhost or staging
EMAIL_USE_TLS = os.environ.get("EMAIL_USE_TLS")
EMAIL_HOST = os.environ.get("EMAIL_HOST")
EMAIL_HOST_USER = os.environ.get("EMAIL_HOST_USER")
EMAIL_HOST_PASSWORD = os.environ.get("EMAIL_HOST_PASSWORD")
EMAIL_PORT = os.environ.get("EMAIL_PORT")
EMAIL_BACKEND = os.environ.get("EMAIL_BACKEND")
DEFAULT_FROM_EMAIL = 'chalktracks@gmail.com'
# CELERY
# CELERY_BROKER_URL = 'redis://redis:6379/0'
# CELERY_RESULT_BACKEND = 'redis://redis:6379/0'
# BROKER_URL = 'redis://localhost:6379/0'
# CELERY_RESULT_BACKEND = 'redis://localhost:6379/'
# CELERY_ACCEPT_CONTENT = ['application/json']
# CELERY_TASK_SERIALIZER = 'json'
# CELERY_RESULT_SERIALIZER = 'json'

REST_FRAMEWORK = {
    # Use Django's standard `django.contrib.auth` permissions,
    # or allow read-only access for unauthenticated users.
    'DEFAULT_PERMISSION_CLASSES': [
        'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly'
    ],
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'rest_framework.authentication.TokenAuthentication',
        'rest_framework.authentication.SessionAuthentication',
    ),
    'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagination',
    'PAGE_SIZE': 10
}

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'console': {
            'format': '%(levelname)s %(asctime)s %(module)s: %(message)s'
        },

    },
    'handlers': {
        'console': {
            'class': 'logging.StreamHandler',
            'formatter': 'console'
        },
    },
    'loggers': {
        '': {
            'handlers': ['console'],
            'level': os.getenv('DJANGO_LOG_LEVEL', 'INFO'),
        },
        'django': {
            'handlers': ['console'],
            'level': os.getenv('DJANGO_LOG_LEVEL', 'INFO'),
        },
        'django.request': {
            'level': 'INFO',
            'handlers': ['console']
        }
        # 'celery': {
        #     'handlers': ['console'],
        #     'level': os.getenv('DJANGO_LOG_LEVEL', 'INFO'),
        # },
    },
}


# STATICFILES_DIRS = [
#     os.path.join(BASE_DIR, 'static'),
# ]

PWA_APP_NAME = 'ChalkTracks'
PWA_APP_DESCRIPTION = "Indoor Climbing Tracker"
PWA_APP_THEME_COLOR = '#000000'
PWA_APP_BACKGROUND_COLOR = '#000000'
PWA_APP_DISPLAY = 'standalone'
PWA_APP_SCOPE = '/'
PWA_APP_ORIENTATION = 'portrait'
PWA_APP_START_URL = '/'
PWA_APP_ICONS = [
    {
        'src': '/static/routes/favicon_io/favicon-32x32.png',
        'sizes': '32x32',
        "type": "image/png",
        "purpose": "any maskable"
    }, {
        "src": "/static/routes/favicon_io/android-chrome-192x192.png",
        "sizes": "192x192",
        "type": "image/png",
        "purpose": "any maskable"
    }, {
        "src": "/static/routes/favicon_io/android-chrome-512x512.png",
        "sizes": "512x512",
        "type": "image/png",
        "purpose": "any maskable"
    }
]

PWA_APP_DIR = 'ltr'
PWA_APP_LANG = 'en-US'

sentry_sdk.init(
    dsn="https://09ce3488b18c4db19820b873eecc30c4@sentry.io/1878812",
    integrations=[DjangoIntegration()],

    # If you wish to associate users to errors (assuming you are using
    # django.contrib.auth) you may enable sending PII data.
    send_default_pii=True
)

[((8, 26, 9, 60), 'os.path.join', 'os.path.join', ({(9, 4, 9, 12): 'BASE_DIR', (9, 14, 9, 39): '"""routes/static/routes/js"""', (9, 41, 9, 59): '"""serviceworker.js"""'}, {}), "(BASE_DIR, 'routes/static/routes/js', 'serviceworker.js')", False, 'import os\n'), ((15, 13, 15, 68), 'os.environ.get', 'os.environ.get', ({(15, 28, 15, 40): '"""SECRET_KEY"""', (15, 42, 15, 67): '"""asdfkhbsadgui87gjsbdfui"""'}, {}), "('SECRET_KEY', 'asdfkhbsadgui87gjsbdfui')", False, 'import os\n'), ((132, 16, 132, 47), 'os.environ.get', 'os.environ.get', ({(132, 31, 132, 46): '"""EMAIL_USE_TLS"""'}, {}), "('EMAIL_USE_TLS')", False, 'import os\n'), ((133, 13, 133, 41), 'os.environ.get', 'os.environ.get', ({(133, 28, 133, 40): '"""EMAIL_HOST"""'}, {}), "('EMAIL_HOST')", False, 'import os\n'), ((134, 18, 134, 51), 'os.environ.get', 'os.environ.get', ({(134, 33, 134, 50): '"""EMAIL_HOST_USER"""'}, {}), "('EMAIL_HOST_USER')", False, 'import os\n'), ((135, 22, 135, 59), 'os.environ.get', 'os.environ.get', ({(135, 37, 135, 58): '"""EMAIL_HOST_PASSWORD"""'}, {}), "('EMAIL_HOST_PASSWORD')", False, 'import os\n'), ((136, 13, 136, 41), 'os.environ.get', 'os.environ.get', ({(136, 28, 136, 40): '"""EMAIL_PORT"""'}, {}), "('EMAIL_PORT')", False, 'import os\n'), ((137, 16, 137, 47), 'os.environ.get', 'os.environ.get', ({(137, 31, 137, 46): '"""EMAIL_BACKEND"""'}, {}), "('EMAIL_BACKEND')", False, 'import os\n'), ((10, 6, 11, 60), 'os.path.join', 'os.path.join', ({(11, 4, 11, 12): 'BASE_DIR', (11, 14, 11, 39): '"""routes/static/routes/js"""', (11, 41, 11, 59): '"""serviceworker.js"""'}, {}), "(BASE_DIR, 'routes/static/routes/js', 'serviceworker.js')", False, 'import os\n'), ((13, 12, 13, 46), 'os.environ.get', 'os.environ.get', (), '', False, 'import os\n'), ((6, 43, 6, 68), 'os.path.abspath', 'os.path.abspath', ({(6, 59, 6, 67): '__file__'}, {}), '(__file__)', False, 'import os\n'), ((19, 16, 19, 67), 'os.environ.get', 'os.environ.get', ({(19, 31, 19, 53): '"""DJANGO_ALLOWED_HOSTS"""', (19, 55, 19, 66): '"""localhost"""'}, {}), "('DJANGO_ALLOWED_HOSTS', 'localhost')", False, 'import os\n'), ((77, 18, 77, 76), 'os.environ.get', 'os.environ.get', ({(77, 33, 77, 45): '"""SQL_ENGINE"""', (77, 47, 77, 75): '"""django.db.backends.sqlite3"""'}, {}), "('SQL_ENGINE', 'django.db.backends.sqlite3')", False, 'import os\n'), ((79, 16, 79, 50), 'os.environ.get', 'os.environ.get', ({(79, 31, 79, 41): '"""SQL_USER"""', (79, 43, 79, 49): '"""user"""'}, {}), "('SQL_USER', 'user')", False, 'import os\n'), ((80, 20, 80, 62), 'os.environ.get', 'os.environ.get', ({(80, 35, 80, 49): '"""SQL_PASSWORD"""', (80, 51, 80, 61): '"""password"""'}, {}), "('SQL_PASSWORD', 'password')", False, 'import os\n'), ((81, 16, 81, 55), 'os.environ.get', 'os.environ.get', ({(81, 31, 81, 41): '"""SQL_HOST"""', (81, 43, 81, 54): '"""localhost"""'}, {}), "('SQL_HOST', 'localhost')", False, 'import os\n'), ((82, 16, 82, 50), 'os.environ.get', 'os.environ.get', ({(82, 31, 82, 41): '"""SQL_PORT"""', (82, 43, 82, 49): '"""5432"""'}, {}), "('SQL_PORT', '5432')", False, 'import os\n'), ((78, 47, 78, 83), 'os.path.join', 'os.path.join', ({(78, 60, 78, 68): 'BASE_DIR', (78, 70, 78, 82): '"""db.sqlite3"""'}, {}), "(BASE_DIR, 'db.sqlite3')", False, 'import os\n'), ((180, 21, 180, 58), 'os.getenv', 'os.getenv', ({(180, 31, 180, 49): '"""DJANGO_LOG_LEVEL"""', (180, 51, 180, 57): '"""INFO"""'}, {}), "('DJANGO_LOG_LEVEL', 'INFO')", False, 'import os\n'), ((184, 21, 184, 58), 'os.getenv', 'os.getenv', ({(184, 31, 184, 49): '"""DJANGO_LOG_LEVEL"""', (184, 51, 184, 57): '"""INFO"""'}, {}), "('DJANGO_LOG_LEVEL', 'INFO')", False, 'import os\n'), ((234, 18, 234, 37), 'sentry_sdk.integrations.django.DjangoIntegration', 'DjangoIntegration', ({}, {}), '()', False, 'from sentry_sdk.integrations.django import DjangoIntegration\n')]