"""
Django settings for PX360 project.

Generated by 'django-admin startproject' using Django 6.0.

For more information on this file, see
https://docs.djangoproject.com/en/6.0/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/6.0/ref/settings/
"""

import os
from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/6.0/howto/deployment-checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = "django-insecure-b!)avw-ibl#m*p-_vw%k4#)*b8a*-(7k4-#6eb8un@=-mksed("

CIPHER_KEY = os.environ.get("CIPHER_KEY", SECRET_KEY)

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
    "django.contrib.admin",
    "django.contrib.auth",
    "django.contrib.contenttypes",
    "django.contrib.sessions",
    "django.contrib.messages",
    "django.contrib.staticfiles",
    "rest_framework",
    # Apps
    "apps.core",
    "apps.accounts",
    "apps.organizations",
    "apps.complaints",
    "apps.observations",
    "apps.feedback",
    "apps.appreciation",
    "apps.dashboard",
    "apps.social",
    "apps.px_sources",
    "apps.analytics",
    "apps.notifications",
    "apps.surveys",
    "apps.ai_engine",
    "apps.callcenter",
    "apps.executive_summary",
    "apps.integrations",
    "apps.journeys",
    "apps.physicians",
    "apps.presentations",
    "apps.projects",
    "apps.px_action_center",
    "apps.rca",
    "apps.references",
    "apps.simulator",
    "apps.standards",
    "django_celery_beat",
]

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",
    # PX Source User Access Control
    "apps.px_sources.middleware.SourceUserRestrictionMiddleware",
    "apps.px_sources.middleware.SourceUserSessionMiddleware",
]

ROOT_URLCONF = "PX360.urls"

TEMPLATES = [
    {
        "BACKEND": "django.template.backends.django.DjangoTemplates",
        "DIRS": [BASE_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",
                "apps.core.context_processors.hospital_context",
                "apps.core.context_processors.sidebar_counts",
            ],
        },
    },
]

WSGI_APPLICATION = "PX360.wsgi.application"


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

DATABASES = {
    "default": {
        "ENGINE": "django.db.backends.sqlite3",
        "NAME": BASE_DIR / "db.sqlite3",
    }
}


# Password validation
# https://docs.djangoproject.com/en/6.0/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/6.0/topics/i18n/

LANGUAGE_CODE = "en-us"

TIME_ZONE = "UTC"

USE_I18N = True

USE_TZ = True


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

STATIC_URL = "static/"

# Celery Configuration
CELERY_BROKER_URL = "redis://localhost:6379/0"
CELERY_RESULT_BACKEND = "redis://localhost:6379/0"
CELERY_ACCEPT_CONTENT = ["json"]
CELERY_TASK_SERIALIZER = "json"
CELERY_RESULT_SERIALIZER = "json"
CELERY_TIMEZONE = TIME_ZONE
CELERY_ENABLE_UTC = True

# Django Celery Beat Scheduler
CELERY_BEAT_SCHEDULER = "django_celery_beat.schedulers:DatabaseScheduler"
LINKEDIN_CLIENT_SECRET = "WPL_AP1.Ek4DeQDXuv4INg1K.mGo4CQ=="
LINKEDIN_REDIRECT_URI = "http://127.0.0.1:8000/social/callback/LI/"
LINKEDIN_WEBHOOK_VERIFY_TOKEN = "your_random_secret_string_123"


# YOUTUBE API CREDENTIALS
# Ensure this matches your Google Cloud Console settings
YOUTUBE_CLIENT_SECRETS_FILE = BASE_DIR / "secrets" / "yt_client_secrets.json"
YOUTUBE_REDIRECT_URI = "http://127.0.0.1:8000/social/callback/YT/"


# Google  REVIEWS Configuration
# Ensure you have your client_secrets.json file at this location
GMB_CLIENT_SECRETS_FILE = BASE_DIR / "secrets" / "gmb_client_secrets.json"
GMB_REDIRECT_URI = "http://127.0.0.1:8000/social/callback/GO/"

# Data upload settings
# Increased limit to support bulk patient imports from HIS
DATA_UPLOAD_MAX_NUMBER_FIELDS = 20000


# X API Configuration
X_CLIENT_ID = "your_client_id"
X_CLIENT_SECRET = "your_client_secret"
X_REDIRECT_URI = "http://127.0.0.1:8000/social/callback/X/"
# TIER CONFIGURATION
# Set to True if you have Enterprise Access
# Set to False for Free/Basic/Pro
X_USE_ENTERPRISE = False


# --- TIKTOK CONFIG ---
TIKTOK_CLIENT_KEY = "your_client_key"
TIKTOK_CLIENT_SECRET = "your_client_secret"
TIKTOK_REDIRECT_URI = "http://127.0.0.1:8000/social/callback/TT/"


# --- META API CONFIG ---
META_APP_ID = "1229882089053768"
META_APP_SECRET = "b80750bd12ab7f1c21d7d0ca891ba5ab"
META_REDIRECT_URI = "https://micha-nonparabolic-lovie.ngrok-free.dev/social/callback/META/"
META_WEBHOOK_VERIFY_TOKEN = "random_secret_string_khanfaheed123456"

EMAIL_LOGO_URL = "http://127.0.0.1:8000/static/img/HH_R_H_Logo.png"
