"""
Django settings for entralon project.

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

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

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

import os
from pathlib import Path
import datetime
import environ
env = environ.Env()
environ.Env.read_env()
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
from django.utils.translation import gettext_lazy as _

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

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-68a96q1(gx6%+4goh831jc&cvkp60m02b)rrp(*2$%s)1$o&5m'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = env.str('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',
    'django.contrib.sites',
    'django.contrib.sitemaps',
    'django.contrib.humanize',
    'django_cleanup.apps.CleanupConfig',
    'django.contrib.gis',
    'django_crontab',
    'django_user_agents',
    'corsheaders',
    'rest_framework',
    'rest_framework_gis',
    'rest_framework_simplejwt',
    'django_filters',
    'rosetta',
    'webp_converter',
    'import_export',
    'django_ckeditor_5',
    'django_select2',
    'widget_tweaks',
    'pg_copy',
    'main',
    'development',
    'developer',
    'blog',
    'user',
    'geo_location',
    'data_scraper',
]

SITE_ID = 1

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

MIDDLEWARE_CLASSES = [
    'django_user_agents.middleware.UserAgentMiddleware',
]


ROOT_URLCONF = 'entralon.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [BASE_DIR / 'templates'],
        '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',
                'webp_converter.context_processors.webp_support',
            ],
        },
    },
]


WSGI_APPLICATION = 'entralon.wsgi.application'


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

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

DATABASES = {
    'default': {
        'ENGINE': 'django.contrib.gis.db.backends.postgis',
        'NAME': env.str('database_name'),
        'USER': env.str('database_user'),
        'PASSWORD': env.str('database_password'),
        'HOST': env.str('database_host'),
        'PORT': env.str('database_port'),
    },
}


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

LANGUAGE_CODE = 'en'

LANGUAGES = [
    ('en', _('English')),
    ('ru', _('Russian')),
    ('fa', _('Persian')),
    ('ar', _('Arabic')),
]

TIME_ZONE = 'UTC'

USE_I18N = True
USE_L10N = True

USE_TZ = True


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

LOCALE_PATHS = (BASE_DIR / "locale", )

STATIC_URL = '/static/'
STATICFILES_DIRS = [BASE_DIR / "assets",]
STATIC_ROOT = BASE_DIR / "static"

MEDIA_URL = '/media/'
MEDIA_ROOT = Path.joinpath(BASE_DIR, 'media')


# Default primary key field type
# https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

customColorPalette = [
        {
            'color': 'hsl(4, 90%, 58%)',
            'label': 'Red'
        },
        {
            'color': 'hsl(340, 82%, 52%)',
            'label': 'Pink'
        },
        {
            'color': 'hsl(291, 64%, 42%)',
            'label': 'Purple'
        },
        {
            'color': 'hsl(262, 52%, 47%)',
            'label': 'Deep Purple'
        },
        {
            'color': 'hsl(231, 48%, 48%)',
            'label': 'Indigo'
        },
        {
            'color': 'hsl(207, 90%, 54%)',
            'label': 'Blue'
        },
    ]


# CKEDITOR_5_CUSTOM_CSS = 'path_to.css' # optional
# CKEDITOR_5_FILE_STORAGE = "editor/upload/" # optional
CKEDITOR_5_USER_LANGUAGE=True
CKEDITOR_5_ALLOW_ALL_FILE_TYPES = False # True all files , Else only image files
# CKEDITOR_5_UPLOAD_FILE_TYPES = ['jpeg', 'pdf', 'png'] # optional
CK_EDITOR_5_UPLOAD_FILE_VIEW_NAME = "custom_upload_file"
CKEDITOR_5_FILE_UPLOAD = "uploads/"
CKEDITOR_5_FILE_UPLOAD_PERMISSION = "staff"
CKEDITOR_5_CONFIGS = {
    'default': {
        'blockToolbar': [
            'paragraph', 'heading1', 'heading2', 'heading3',
            '|',
            'bulletedList', 'numberedList',
            '|',
            'blockQuote',
        ],
        'toolbar': ['heading', '|', 'outdent', 'indent', '|', 'bold', 'italic', 'link', 'underline', 'strikethrough',
        'code','subscript', 'superscript', 'highlight', '|', 'codeBlock', 'sourceEditing', 'insertImage',
                    'bulletedList', 'numberedList', 'todoList', '|',  'blockQuote', 'imageUpload', '|',
                    'fontSize', 'fontFamily', 'fontColor', 'fontBackgroundColor', 'mediaEmbed', 'removeFormat',
                    'insertTable',],
        'image': {
            'toolbar': ['imageTextAlternative', '|', 'imageStyle:alignLeft',
                        'imageStyle:alignRight', 'imageStyle:alignCenter', 'imageStyle:side',  '|'],
            'styles': [
                'full',
                'side',
                'alignLeft',
                'alignRight',
                'alignCenter',
            ]

        },
        'table': {
            'contentToolbar': [ 'tableColumn', 'tableRow', 'mergeTableCells',
            'tableProperties', 'tableCellProperties' ],
            'tableProperties': {
                'borderColors': customColorPalette,
                'backgroundColors': customColorPalette
            },
            'tableCellProperties': {
                'borderColors': customColorPalette,
                'backgroundColors': customColorPalette
            }
        },
        'heading' : {
            'options': [
                { 'model': 'paragraph', 'title': 'Paragraph', 'class': 'ck-heading_paragraph' },
                { 'model': 'heading1', 'view': 'h1', 'title': 'Heading 1', 'class': 'ck-heading_heading1' },
                { 'model': 'heading2', 'view': 'h2', 'title': 'Heading 2', 'class': 'ck-heading_heading2' },
                { 'model': 'heading3', 'view': 'h3', 'title': 'Heading 3', 'class': 'ck-heading_heading3' }
            ]
        }
    },
    'extends': {
        'blockToolbar': [
            'paragraph', 'heading1', 'heading2', 'heading3',
            '|',
            'bulletedList', 'numberedList',
            '|',
            'blockQuote',
        ],
        'toolbar': ['heading', '|', 'outdent', 'indent', '|', 'bold', 'italic', 'link', 'underline', 'strikethrough',
        'code','subscript', 'superscript', 'highlight', '|', 'codeBlock', 'sourceEditing', 'insertImage',
                    'bulletedList', 'numberedList', 'todoList', '|',  'blockQuote', 'imageUpload', '|',
                    'fontSize', 'fontFamily', 'fontColor', 'fontBackgroundColor', 'mediaEmbed', 'removeFormat',
                    'insertTable',],
        'image': {
            'toolbar': ['imageTextAlternative', '|', 'imageStyle:alignLeft',
                        'imageStyle:alignRight', 'imageStyle:alignCenter', 'imageStyle:side',  '|'],
            'styles': [
                'full',
                'side',
                'alignLeft',
                'alignRight',
                'alignCenter',
            ]

        },
        'table': {
            'contentToolbar': [ 'tableColumn', 'tableRow', 'mergeTableCells',
            'tableProperties', 'tableCellProperties' ],
            'tableProperties': {
                'borderColors': customColorPalette,
                'backgroundColors': customColorPalette
            },
            'tableCellProperties': {
                'borderColors': customColorPalette,
                'backgroundColors': customColorPalette
            }
        },
        'heading' : {
            'options': [
                { 'model': 'paragraph', 'title': 'Paragraph', 'class': 'ck-heading_paragraph' },
                { 'model': 'heading1', 'view': 'h1', 'title': 'Heading 1', 'class': 'ck-heading_heading1' },
                { 'model': 'heading2', 'view': 'h2', 'title': 'Heading 2', 'class': 'ck-heading_heading2' },
                { 'model': 'heading3', 'view': 'h3', 'title': 'Heading 3', 'class': 'ck-heading_heading3' }
            ]
        }
    },
    'list': {
        'properties': {
            'styles': 'true',
            'startIndex': 'true',
            'reversed': 'true',
        }
    }
}

import mimetypes
mimetypes.add_type("application/javascript", ".js", True)

ROSETTA_ENABLE_TRANSLATION_SUGGESTIONS = True
ROSETTA_ENABLE_TRANSLATION_SUGGESTIONS = True
YANDEX_TRANSLATE_KEY = "trnsl.1.1.20200526T102728Z.3f83373793bf4144.78d4a3afeceaf7b5ee0a38717e0805f84e89f141"
# OPENAI_API_KEY = ""
# ROSETTA_LANGUAGE_GROUPS = True
ROSETTA_SHOW_AT_ADMIN_PANEL = True

ENCODING = 'utf-8'

CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
        'LOCATION': Path.joinpath(BASE_DIR, 'tmp'),
    }
}

SELECT2_CACHE_BACKEND = 'default'
# SELECT2_I18N_PATH = '/static/django_select2/i18n/'
# SELECT2_JS = ['/static/django_select2/select2.full.min.js','/static/django_select2/django_select2.js']
# SELECT2_CSS = ['/static/django_select2/select2.min.css', '/static/django_select2/django_select2.css']

# SESSION_COOKIE_AGE = 3600
SESSION_COOKIE_HTTPONLY = True
SESSION_COOKIE_NAME = "entralon-id"
# SESSION_COOKIE_SECURE = True
# SESSION_EXPIRE_AT_BROWSER_CLOSE = True
SESSION_SAVE_EVERY_REQUEST = True
SECURE_CROSS_ORIGIN_OPENER_POLICY = None


FILE_UPLOAD_MAX_MEMORY_SIZE = 1 * (2**20) # in bytes for MB -> *(2**20) -> steam file upload by cache
DATA_UPLOAD_MAX_MEMORY_SIZE = 10 * (2**20) # in bytes for MB -> *(2**20) -> max upload size
FILE_UPLOAD_TEMP_DIR = Path.joinpath(BASE_DIR, 'tmp')


dt = datetime.datetime.now()
nm = dt.strftime("%Y%m")
path = os.path.join(BASE_DIR, f'log/cron/{nm}')
if not os.path.exists(path):
    os.makedirs(path)

"""
Defines a set of scheduled tasks (cron jobs) to be executed at regular intervals.

The CRONJOBS setting is a list of tuples, where each tuple contains the following:
- A cron schedule expression (e.g. '*/7 * * * *' to run every 7 minutes)
- The path to the Python function that should be executed
- The path to a log file where the output of the cron job should be written

The cron jobs defined here include:
- Translating development content every 7 minutes
- Adding currency rates daily at 8 AM
- Translating developer content every 8 minutes
- Translating country data every 9 minutes
- Translating city data every 11 minutes
- Adding new blog posts hourly
('minutes hour dayOfMonth month dayOfWeek', 'app.cron.function', f'>> path_of_cron_log'),
"""
CRONJOBS = [
    
    ('*/5 * * * *', 'development.cron.get_panorama_detail', f'>> {path}/get_panorama_detail_{nm}.log'),
    ('*/2 * * * *', 'development.cron.get_street_view_images', f'>> {path}/get_street_view_images_{nm}.log'),
    ('17 2 * * *', 'development.cron.get_onh_station_json', f'>> {path}/get_onh_station_json_{nm}.log'),
    ('17 2 * * *', 'development.cron.get_onh_district_json', f'>> {path}/get_onh_district_json_{nm}.log'),
    ('17 2 * * *', 'development.cron.get_onh_postcode_json', f'>> {path}/get_onh_postcode_json_{nm}.log'),
    ('17 2 * * *', 'development.cron.get_onh_area_json', f'>> {path}/get_onh_area_json_{nm}.log'),
    ('17 2 * * *', 'development.cron.get_onh_zone_json', f'>> {path}/get_onh_zone_json_{nm}.log'),
    ('19 */6 * * *', 'development.cron.set_development_station', f'>> {path}/set_development_station_{nm}.log'),
    ('19 */6 * * *', 'development.cron.set_development_district', f'>> {path}/set_development_district_{nm}.log'),
    ('19 */6 * * *', 'development.cron.set_development_postcode', f'>> {path}/set_development_postcode_{nm}.log'),
    ('19 */6 * * *', 'development.cron.set_development_area', f'>> {path}/set_development_area_{nm}.log'),
    ('19 */6 * * *', 'development.cron.set_development_zone', f'>> {path}/set_development_zone_{nm}.log'),
    ('*/4 * * * *', 'development.cron.set_ready_to_move', f'>> {path}/set_ready_to_move_{nm}.log'),
    ('37 */6 * * *', 'development.cron.set_development_geo_json', f'>> {path}/set_development_geo_json_{nm}.log'),
    ('47 */6 * * *', 'development.cron.set_development_translate_geo_json', f'>> {path}/set_development_translate_geo_json_{nm}.log'),
    ('*/5 * * * *', 'development.cron.development_description', f'>> {path}/development_description_{nm}.log'),
    ('*/5 * * * *', 'development.cron.create_development_faq', f'>> {path}/create_development_faq_{nm}.log'),
    ('*/7 * * * *', 'development.cron.development_summarize', f'>> {path}/development_summarize_{nm}.log'),
    ('9 5 * * *', 'development.cron.create_filter_seo_objects', f'>> {path}/create_filter_seo_objects_{nm}.log'),
    ('* * * * *', 'development.cron.get_filter_page_text', f'>> {path}/get_filter_page_text_{nm}.log'),
    ('* * * * *', 'geo_location.cron.get_location_raw', f'>> {path}/get_location_raw_{nm}.log'),
    ('*/2 * * * *', 'geo_location.cron.set_location_data', f'>> {path}/set_location_data_{nm}.log'),
    ('*/2 * * * *', 'geo_location.cron.set_location_translate_data', f'>> {path}/set_location_translate_data_{nm}.log'),
    ('*/10 * * * *', 'geo_location.cron.get_country_data', f'>> {path}/get_country_data_{nm}.log'),
    ('*/15 * * * *', 'geo_location.cron.set_country_coordinates', f'>> {path}/set_country_coordinates_{nm}.log'),
    ('18 3 * * *', 'geo_location.cron.location_info', f'>> {path}/location_info_{nm}.log'),
    ('58 */13 * * *', 'data_scraper.cron.get_data_1nh', f'>> {path}/get_data_1nh_{nm}.log'),
    ('*/21 * * * *', 'data_scraper.cron.parse_development_data_1nh', f'>> {path}/parse_development_data_1nh_{nm}.log'),
    ('*/17 * * * *', 'data_scraper.cron.parse_filter_data_1nh', f'>> {path}/parse_filter_data_1nh_{nm}.log'),
    ('*/13 * * * *', 'data_scraper.cron.parse_json_development_data_1nh', f'>> {path}/parse_json_development_data_1nh_{nm}.log'),
    ('*/7 * * * *', 'data_scraper.cron.download_development_data_1nh', f'>> {path}/download_development_data_1nh_{nm}.log'),
    ('*/11 * * * *', 'data_scraper.cron.create_development', f'>> {path}/create_development_{nm}.log'),
    ('59 */23 * * *', 'data_scraper.cron.get_data_1nh_developer', f'>> {path}/get_data_1nh_developer_{nm}.log'),
    ('*/5 * * * *', 'data_scraper.cron.create_developer', f'>> {path}/create_developer_{nm}.log'),
    ('*/5 * * * *', 'data_scraper.cron.download_development_gallery_1nh', f'>> {path}/download_development_gallery_1nh_{nm}.log'),
    ('*/5 * * * *', 'data_scraper.cron.add_attachment_to_development', f'>> {path}/add_attachment_to_development_{nm}.log'),
    ('5 6 * * *', 'data_scraper.cron.delete_temp_files', f'>> {path}/delete_temp_files_{nm}.log'),
    ('7 7 * * *', 'data_scraper.cron.get_news_data_1nh', f'>> {path}/get_news_data_1nh_{nm}.log'),
    ('*/3 * * * *', 'data_scraper.cron.parse_onh_news', f'>> {path}/parse_onh_news_{nm}.log'),
    ('* * * * *', 'main.cron.footer_menu_translate', f'>> {path}/footer_menu_translate_{nm}.log'),
    ('9 * * * *', 'main.cron.create_filter_list', f'>> {path}/create_filter_list_{nm}.log'),
    ('0 0 * * *', 'main.cron.create_site_map', f'>> {path}/create_site_map_{nm}.log'),
    ('0 1 * * *', 'main.cron.create_sitemap_file', f'>> {path}/create_sitemap_file_{nm}.log'),
]
if not DEBUG:
    CRONJOBS += [
        # ('* * * * *', 'blog.cron.add_blog_post', f'>> {path}/add_blog_post_{nm}.log'),
        ('0 8 * * *', 'development.cron.add_currencies_rate', f'>> {path}/add_currencies_rate_{nm}.log'),
        # ('*/7 * * * *', 'development.cron.translate_development', f'>> {path}/translate_development_{nm}.log'),
        # ('*/5 * * * *', 'development.cron.translate_flats', f'>> {path}/translate_flats_{nm}.log'),
        # ('*/5 * * * *', 'development.cron.translate_payment_option', f'>> {path}/translate_payment_option_{nm}.log'),
        # ('*/15 * * * *', 'development.cron.translate_features', f'>> {path}/translate_features_{nm}.log'),
        # ('*/15 * * * *', 'development.cron.translate_building_type', f'>> {path}/translate_building_type_{nm}.log'),
        # ('*/15 * * * *', 'development.cron.translate_rank_element', f'>> {path}/translate_rank_element_{nm}.log'),
        # ('*/15 * * * *', 'development.cron.translate_development_offer', f'>> {path}/translate_development_offer_{nm}.log'),
        # ('*/15 * * * *', 'development.cron.translate_payment_plan', f'>> {path}/translate_payment_plan_{nm}.log'),
        # ('*/5 * * * *', 'development.cron.add_english_seo_text', f'>> {path}/add_english_seo_text_{nm}.log'),
        # ('*/5 * * * *', 'development.cron.translate_seo_text', f'>> {path}/translate_seo_text_{nm}.log'),
        # ('* * * * *', 'development.cron.paraphrase_filter_page_text', f'>> {path}/paraphrase_filter_page_text_{nm}.log'),
        # ('* * * * *', 'development.cron.translate_filter_page_text', f'>> {path}/translate_filter_page_text_{nm}.log'),
        # ('*/8 * * * *', 'developer.cron.translate_developer', f'>> {path}/translate_developer_{nm}.log'),
        # ('*/2 * * * *', 'developer.cron.developer_description', f'>> {path}/developer_description_{nm}.log'),
        # ('*/9 * * * *', 'geo_location.cron.translate_country', f'>> {path}/translate_country_{nm}.log'),
        # ('*/11 * * * *', 'geo_location.cron.translate_city', f'>> {path}/translate_city_{nm}.log'),
        # ('* * * * *', 'main.cron.faq_translate', f'>> {path}/faq_translate_{nm}.log'),
        # ('* * * * *', 'main.cron.send_lead', f'>> {path}/send_lead_{nm}.log'),
        # ('* * * * *', 'main.cron.prompt_checker', f'>> {path}/prompt_checker_{nm}.log'),
        ('*/5 * * * *', 'data_scraper.cron.onh_news_paraphrase', f'>> {path}/onh_news_paraphrase_{nm}.log'),
    ]


REST_FRAMEWORK = {
    'DEFAULT_RENDERER_CLASSES': [
        'rest_framework.renderers.JSONRenderer',
        'rest_framework.renderers.BrowsableAPIRenderer', # use for view in html and api format
    ],
    'DEFAULT_PARSER_CLASSES': [
        'rest_framework.parsers.JSONParser', # use for only json requests
        'rest_framework.parsers.FormParser', # user for forms without files
        'rest_framework.parsers.MultiPartParser' # use for form with multiple parts or files
    ],
    'DEFAULT_FILTER_BACKENDS': [
        'django_filters.rest_framework.DjangoFilterBackend',
    ],
    'DEFAULT_PERMISSION_CLASSES': (
        # 'rest_framework.permissions.IsAuthenticated',
    ),
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'rest_framework_simplejwt.authentication.JWTAuthentication',
    ),
    'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
    'PAGE_SIZE': 10,
}

SIMPLE_JWT = {
    'ACCESS_TOKEN_LIFETIME': datetime.timedelta(minutes=60),
    'SLIDING_TOKEN_REFRESH_LIFETIME': datetime.timedelta(days=1),
    'SLIDING_TOKEN_LIFETIME': datetime.timedelta(days=30),
    'SLIDING_TOKEN_REFRESH_LIFETIME_LATE_USER': datetime.timedelta(days=1),
    'SLIDING_TOKEN_LIFETIME_LATE_USER': datetime.timedelta(days=30),
}




DATA_UPLOAD_MAX_NUMBER_FIELDS = 10240
SECURE_HSTS_INCLUDE_SUBDOMAINS = True
SECURE_REFERRER_POLICY = "origin-when-cross-origin"

CSRF_TRUSTED_ORIGINS = ['http://127.0.0.1','http://127.0.0.1:8000', 'http://192.168.110.247:8000', 'http://127.0.0.1:3000', 'http://localhost:3000', 'https://api-dev.entralon.com','https://api-stage.entralon.com', 'https://api.entralon.com', 'https://dev.entralon.com','https://stage.entralon.com', 'https://entralon.com']

CORS_ALLOWED_ORIGINS = ['https://api-dev.entralon.com','https://api-stage.entralon.com', 'https://api.entralon.com', 'https://dev.entralon.com','https://stage.entralon.com', 'https://entralon.com','http://127.0.0.1','http://127.0.0.1:8000', 'http://192.168.110.247:8000', 'http://127.0.0.1:3000', 'http://localhost:3000']
# CORS_ALLOW_ALL_ORIGINS = True
CORS_ALLOW_PRIVATE_NETWORK = True

CORS_ALLOW_METHODS = [
    "DELETE",
    "GET",
    "OPTIONS",
    "PATCH",
    "POST",
    "PUT",
]


from corsheaders.defaults import default_headers
CORS_ALLOW_HEADERS = [
    *default_headers,
    "referrer",
    "Access-Control-Allow-Origin",
    "Access-Control-Allow-Credentials"
]


CORS_EXPOSE_HEADERS = [
    'Access-Control-Allow-Origin',
    'Access-Control-Allow-Credentials'
]

CORS_ORIGIN_WHITELIST = [
    'https://dev.entralon.com',
    'https://entralon.com',
    'https://api-dev.entralon.com',
    'http://127.0.0.1:8000',
    'http://127.0.0.1:3000',

]

CORS_ALLOW_CREDENTIALS = True
CORS_ALLOW_PRIVATE_NETWORK = True
API_TOKEN_EXPIRE = 3600 * 24 * 365
API_USER_EXPIRE = 3600 * 24 * 365

API_TOKEN_LENGTH = 10
API_CUSTOMER_TOKEN_LENGTH = 10

USER_AGENTS_CACHE = 'default'

IPWARE_META_PRECEDENCE_ORDER = (
     'HTTP_X_FORWARDED_FOR', 
     'X_FORWARDED_FOR',  # <client>, <proxy1>, <proxy2>
     'HTTP_CLIENT_IP',
     'HTTP_X_REAL_IP',
     'HTTP_X_FORWARDED',
     'HTTP_X_CLUSTER_CLIENT_IP',
     'HTTP_FORWARDED_FOR',
     'HTTP_FORWARDED',
     'HTTP_VIA',
     'REMOTE_ADDR',
 )

LOGIN_URL = '/master/login/'
LOGIN_REDIRECT_URL = '/master/'
LOGOUT_REDIRECT_URL = '/master/login/'

PG_COPY_BACKUP_PATH = 'db_backup'

PROJECT_PUBLIC_FILE = Path.joinpath(BASE_DIR, 'keys/pr/'+env.str("secret_key"))
PROJECT_PRIVATE_FILE = Path.joinpath(BASE_DIR, 'keys/pr/'+env.str("public_key"))



AUTHENTICATION_BACKENDS = [
    "django.contrib.auth.backends.ModelBackend",
]

OPEN_ROUTE_API_KEY = env.str('open_route_key')

CACHE_TIME=env.int('CACHE_TIME', default=1500)

import sentry_sdk

sentry_sdk.init(
    dsn=env.str('SENTRY_DSN'),
    # Set traces_sample_rate to 1.0 to capture 100%
    # of transactions for tracing.
    traces_sample_rate=1.0,
    _experiments={
        # Set continuous_profiling_auto_start to True
        # to automatically start the profiler on when
        # possible.
        "continuous_profiling_auto_start": True,
    },
)

INTERNAL_IPS = [
    # ...
    "127.0.0.1",
    # ...
]

#S3 BUCKETS CONFIG
AWS_ACCESS_KEY_ID = 'TD1JTZHPPBY10GPBGZQG'
AWS_SECRET_ACCESS_KEY = 'qPSY85nuxckBsXjdmRURogYHlDeSra2zbFZDW6x5'
AWS_STORAGE_BUCKET_NAME = 'entralon-static'
AWS_STATIC_BUCKET_NAME = 'entralon-static'
AWS_S3_FILE_OVERWRITE = False  # (optional: default is True) Set to False if you want to have extra characters appended.
AWS_DEFAULT_ACL = 'public-read' # (optional; default is None) which means the file will inherit the bucket’s permission
AWS_S3_VERIFIED = True
AWS_SERVICE_NAME = 's3'
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
AWS_S3_CUSTOM_DOMAIN = 'entralon.nbg1.your-objectstorage.com'
AWS_S3_MEDIA_DOMAIN = 'entralon.nbg1.your-objectstorage.com' 
AWS_S3_USERMEDA_DOMAIN = 'entralon.nbg1.your-objectstorage.com' 
AWS_S3_ENDPOINT_URL = 'entralon.nbg1.your-objectstorage.com'
AWS_S3_STATIC_DOMAIN = "entralon.nbg1.your-objectstorage.com"