from .base import *
from .unfold_conf import *


ALLOWED_HOSTS = ['127.0.0.1', 'localhost', DOMAIN, API_DOMAIN, '0.0.0.0', "185.110.189.208", 'www.google.com', 'google.com']
CSRF_TRUSTED_ORIGINS = [
    f"https://{DOMAIN}",
    f"http://{DOMAIN}",
    f"https://{API_DOMAIN}",
    f"http://{API_DOMAIN}",
]
# CORS_ALLOWED_ORIGINS = [f"https://{API_DOMAIN}", f"http://{API_DOMAIN}",
#                         f"http://{DOMAIN}", f"https://{DOMAIN}", ]
# import re
# CORS_ALLOWED_ORIGIN_REGEXES = [
#     re.compile(r'^https?://(?:\w+\.)?{}$'.format(re.escape(API_DOMAIN))),
#     re.compile(r'^https?://(?:\w+\.)?{}$'.format(re.escape(DOMAIN))),
#     re.compile(r'^https?://(?:\w+\.)?localhost:\d+$'),
#     re.compile(r'^https?://(?:\w+\.)?127\.0\.0\.1:\d+$'),
# ]


CORS_ALLOW_ALL_ORIGINS = True
# database postgres
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': os.getenv("DB_NAME"),
        'USER': os.getenv("DB_USER"),
        'PASSWORD': os.getenv("DB_PASSWORD"),
        'HOST': os.getenv("DB_HOST"),
        'PORT': os.getenv("DB_PORT"),
    }
}

STORAGES =  {
    "default": {
        "BACKEND": 'core.storages.MediaStorage',
    },
    "staticfiles": {
        "BACKEND": "django.contrib.staticfiles.storage.StaticFilesStorage",
    },
}

MEDIA_URL = 'https://c262408.parspack.net/'
MEDIA_ROOT = '/app/media'

STATIC_URL = '/shop_static/'
STATIC_ROOT = '/app/static'


# ==============================================================================
# django cerery
# ==============================================================================

CELERY_BROKER_URL = "redis://redis:6379/0"
CELERY_RESULT_BACKEND = "redis://redis:6379/0"
CELERY_TIMEZONE = "UTC"
CELERY_BEAT_SCHEDULER = 'django_celery_beat.schedulers:DatabaseScheduler'

from celery.schedules import crontab

CELERY_BEAT_SCHEDULE = {
    'update-prices-every-minute': {
        'task': 'product.tasks.update_prices',
        'schedule': crontab(minute='*'),
    },
    'update-bank-record-every-minute': {
        'task': 'order.tasks.udpate_bank_status',
        'schedule': crontab(minute='*'),
    },
    'generate-daily-shop-reports': {
        'task': 'order.tasks.generate_daily_shop_reports',
        'schedule': crontab(hour=0, minute=5),  # Run daily at 00:05 UTC
    },
}

# ==============================================================================
# to avoid gateway post problem
# ==============================================================================

USE_X_FORWARDED_HOST = True
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')