"""
Django settings for AIchatbot project.

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

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

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

from pathlib import Path
from decouple import config
import os

BASE_DIR = Path(__file__).resolve().parent.parent

SECRET_KEY = 'django-insecure-hg9%9-1yn8h2q+oy8=yt_j$b*52wd=6+@sm*uud#xdl9(mjblu'

DEBUG = True

ALLOWED_HOSTS = ["*"]

# YEH LINE FIX KI:
CHATBOT_API_TOKEN = config("CHATBOT_API_TOKEN", default=None)


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'chatbot',
    "corsheaders",
    'QuestionAnswer',
    'flashcards',
    'questionbank',
]

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

ROOT_URLCONF = 'AIchatbot.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',
            ],
        },
    },
]

CORS_ALLOWED_ORIGINS = [
    "http://127.0.0.1:8000"
]

WSGI_APPLICATION = 'AIchatbot.wsgi.application'


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

DATABASES = {
    'default': {
        "ENGINE": "django.db.backends.mysql",
        "NAME": "prakharai_lms",
        "USER": "prakharai_user",
        "PASSWORD": "!1Fq)WM_x{b*p;7B",
        "HOST": "localhost",
        "PORT": "3306",
    }
}


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

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'Asia/Kolkata'

USE_I18N = True

USE_TZ = True


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

STATIC_URL = 'static/'

STATICFILES_DIRS = [BASE_DIR / 'static',]

STATIC_ROOT = BASE_DIR / 'staticfiles'


# Email
# https://docs.djangoproject.com/en/6.1/topics/email/#topic-email-configuration

MAILERS = {
    'default': {
        'BACKEND': 'django.core.mail.backends.console.EmailBackend',
    },
}



MODEL_API_BASE_URL = config(
    "MODEL_API_BASE_URL",
    default="http://192.168.88.22:1234/v1"
)

MODEL_API_ENDPOINT = config(
    "MODEL_API_ENDPOINT",
    default="http://192.168.88.22:1234/v1/chat/completions"
)

MODEL_API_TIMEOUT = config(
    "MODEL_API_TIMEOUT",
    default=30,
    cast=int
)

MODEL_API_KEY = config(
    "MODEL_API_KEY",
    default="lm-studio"
)

MODEL_NAME = config(
    "MODEL_NAME",
    default="qwen2.5-coder-14b-instruct"
)


# settings.py




#env = environ.Env()
#environ.Env.read_env()

MODEL_API_CONFIG = {
    "BASE_URL": config("MODEL_API_BASE_URL", default="http://192.168.88.22:1234/v1"),
    "ENDPOINT_URL": config("MODEL_API_ENDPOINT", default="http://192.168.88.22:1234/v1/chat/completions"),
    "TIMEOUT": config("MODEL_API_TIMEOUT", default=30, cast=int),
    "API_KEY": config("MODEL_API_KEY", default="lm-studio"),
    "MODEL_NAME": config("MODEL_NAME", default="qwen2.5-coder-14b-instruct"),
}


LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
        'null': {
            'class': 'logging.NullHandler',
        },
    },
    'loggers': {
        'django.server': {
            'handlers': ['null'],
            'level': 'CRITICAL',  # Suppresses INFO and WARNING logs (like broken pipes)
            'propagate': False,
        },
    },
}
