"""
CORE CONSTANTS

"""
import os
from pathlib import Path


class MsbConfigNames:
	MSB_JWT_VERIFY_OWNER = "MSB_JWT_VERIFY_OWNER"
	MSB_JWT_TRUSTED_OWNERS = "MSB_JWT_TRUSTED_OWNERS"
	MSB_JWT_VERIFY_SUBSCRIPTIONS = "MSB_JWT_VERIFY_SUBSCRIPTIONS"
	MSB_JWT_VERIFY_ENVIRONMENT = "MSB_JWT_VERIFY_ENVIRONMENT"
	MSB_DB_ENCRYPT_PRIVATE_FIELDS = "MSB_DB_ENCRYPT_PRIVATE_FIELDS"
	MSB_DB_PK_IS_PRIVATE_FIELD = "MSB_DB_PK_IS_PRIVATE_FIELD"
	MSB_ISR_TOKEN = "MSB_ISR_TOKEN"

	API_GATEWAY_URL = 'API_GATEWAY_URL'
	USER_SERVICE_URL = 'USER_SERVICE_URL'
	EMPLOYEE_SERVICE_URL = 'EMPLOYEE_SERVICE_URL'
	LEAVE_SERVICE_URL = 'LEAVE_SERVICE_URL'
	PROJECT_SERVICE_URL = 'PROJECT_SERVICE_URL'
	CONF_SERVICE_URL = 'CONF_SERVICE_URL'
	NOTIFICATION_SERVICE_URL = 'NOTIFICATION_SERVICE_URL'
	AUTOPILOT_SERVICE_URL = 'AUTOPILOT_SERVICE_URL'
	MSB_DEFAULT_BRODCAST_QUEUES = 'MSB_DEFAULT_BRODCAST_QUEUES'


class EnvDefaults:
	MSB_JWT_VERIFY_OWNER = False
	MSB_JWT_TRUSTED_OWNERS = []
	MSB_DB_ENCRYPT_PRIVATE_FIELDS = False
	MSB_DB_ENCRYPT_PROTECTED_FIELDS = False
	MSB_DB_PK_IS_PRIVATE_FIELD = False
	MSB_JWT_VERIFY_SUBSCRIPTIONS = False
	MSB_JWT_VERIFY_ENVIRONMENT = False

	# allow admin module
	ALLOW_ADMIN_URL = False

	# Secure csrf cookie
	CSRF_COOKIE_SECURE = True

	# Secure session cookie
	SESSION_COOKIE_SECURE = True

	# make csrf cokkied http only
	CSRF_COOKIE_HTTPONLY = True

	# make csrf cokkie http only
	SESSION_COOKIE_HTTPONLY = True

	# secure the ssl redirect
	SECURE_SSL_REDIRECT = True

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

	CORS_ALLOW_HEADERS = [
		"accept", "accept-encoding", "authorization", "content-type",
		"dnt", "origin", "user-agent", "x-csrftoken",
		"x-requested-with",
	]

	CORS_PREFLIGHT_MAX_AGE = 86400

	CORS_ALLOW_CREDENTIALS = True


class NameConst:
	"""
	ENV CONSTANT NAMES
	"""
	ENV_LOAD_STATUS_KEY_NAME = 'ENV_CONFIG_LOADED'
	DOT_ENV_FILE_NAME = ".env"
	LOCAL_CONFIG_FILE_PREFIX = "local"
	ENVIRONMENT_VARIABLE_NAME = "ENVIRONMENT"
	DEBUG_VARIABLE_NAME = "DEBUG"

	"""
	CONSTANT DIRECTORY NAMES
	"""
	APP_DIR_NAME = "app"
	RESOURCES_DIR_NAME = "resources"
	WRITABLE_DIR_NAME = "writable"
	FIXTURES_DIR_NAME = "fixtures"

	DEFAULT_FIXTURE_DIR_NAME = "base"
	PROD_FIXTURE_DIR_NAME = "prod"
	TEST_FIXTURE_DIR_NAME = "test"

	RESOURCE_CONFIG_DIR_NAME = "config"
	SETUP_SCRIPTS_DIR_NAME = "setup"
	TEST_DATA_DIR_NAME = "test_data"
	LOGS_DIR_NAME = "logs"
	MIGRATIONS_DIR_NAME = "migrations"

	"""
	CONSTANT ENVIRONMENT NAMES
	"""
	PROD_ENV_NAME = "prod"
	STAGE_ENV_NAME = "stage"
	TEST_ENV_NAME = "test"
	DEV_ENV_NAME = "dev"
	LOCAL_ENV_NAME = "local"

	ENV_NAME_LIST = [LOCAL_ENV_NAME, DEV_ENV_NAME, TEST_ENV_NAME, STAGE_ENV_NAME, PROD_ENV_NAME]
	DEV_OR_TEST_ENV_NAMES_LIST = [LOCAL_ENV_NAME, DEV_ENV_NAME, TEST_ENV_NAME]
	DEV_ENV_NAMES_LIST = [LOCAL_ENV_NAME, DEV_ENV_NAME]
	"""
	CONSTANT FILE NAMES
	"""
	PROD_ENV_FILE_NAME = ".env"
	DEV_ENV_FILE_NAME = ".env.local"

	"""
	CONSTANT DATABASE NAMES
	"""
	DEFAULT_DATABASE_NAME = "default"
	LOGS_DATABASE_NAME = "logs"

	YAML_FILE_EXTENTION_NAME = "yaml"

	"""
	CONSTANT SERVICES NAMES
	"""
	API_GATEWAY_SERVICE_NAME = "API_GATEWAY"
	USER_SERVICE_NAME = 'USER_SERVICE'
	EMPLOYEE_SERVICE_NAME = 'EMPLOYEE_SERVICE'
	LEAVE_SERVICE_NAME = 'LEAVE_SERVICE'
	PROJECT_SERVICE_NAME = 'PROJECT_SERVICE'
	CONF_SERVICE_NAME = 'CONF_SERVICE'
	NOTIFICATION_SERVICE_NAME = 'NOTIFICATION_SERVICE'
	AUTOPILOT_SERVICE_NAME = 'AUTOPILOT_SERVICE'

	"""
		CONSTANT  NAMES FOR VALIDATION
	"""
	BULK_SCHEMA_NAME = 'schema_list'

	"""
		ASYNC TASK AND QUEUE NAMES
	"""
	ASYNC_TASK_NAME = 'async_task'
	EMAIL_NOTIFICATION_TASK_NAME = 'email_notification'
	YAMMER_NOTIFICATION_TASK_NAME = 'yammer_notification'
	NOTIFICATION_QUEUE_NAME = 'notification_management'
	SERVICE_NAME = 'HRIN-MSB'

	"""
		DEFAULT CELERY QUEUE NAMES
	"""
	USER_SERVICE_QUEUE_NAME = 'user_service_queue'
	EMPLOYEE_SERVICE_QUEUE_NAME = 'employee_service_queue'
	LEAVE_SERVICE_QUEUE_NAME = 'leave_service_queue'
	PROJECT_SERVICE_QUEUE_NAME = 'project_service_queue'
	CONF_SERVICE_QUEUE_NAME = 'conf_service_queue'
	NOTIFICATION_SERVICE_QUEUE_NAME = 'notification_service_queue'
	AUTOPILOT_SERVICE_QUEUE_NAME = 'autopilot_service_queue'


class PathConst:
	# path list under root directory
	BASE_DIR_PATH = Path(
		Path(__file__).__str__().replace(NameConst.RESOURCES_DIR_NAME, NameConst.APP_DIR_NAME).__str__() \
			.replace(NameConst.RESOURCES_DIR_NAME, NameConst.APP_DIR_NAME) \
			.replace('.venv', NameConst.APP_DIR_NAME)
			.split(NameConst.APP_DIR_NAME)[0]
	)
	APP_DIR_PATH = BASE_DIR_PATH.joinpath(NameConst.APP_DIR_NAME)
	WRITABLE_DIR_PATH = BASE_DIR_PATH.joinpath(NameConst.WRITABLE_DIR_NAME)
	RESOURCE_DIR_PATH = BASE_DIR_PATH.joinpath(NameConst.RESOURCES_DIR_NAME)

	PROD_ENV_FILE_PATH = BASE_DIR_PATH.joinpath(NameConst.PROD_ENV_FILE_NAME)
	DEV_ENV_FILE_PATH = BASE_DIR_PATH.joinpath(NameConst.DEV_ENV_FILE_NAME)

	# path list under writable directory
	LOGS_DIR_PATH = WRITABLE_DIR_PATH.joinpath(NameConst.LOGS_DIR_NAME)

	# path list under resources directory
	FIXTURES_DIR_PATH = RESOURCE_DIR_PATH.joinpath(NameConst.FIXTURES_DIR_NAME)
	RESOURCE_CONFIG_DIR_PATH = RESOURCE_DIR_PATH.joinpath(NameConst.RESOURCE_CONFIG_DIR_NAME)
	SETUP_SCRIPTS_DIR_PATH = RESOURCE_DIR_PATH.joinpath(NameConst.SETUP_SCRIPTS_DIR_NAME)
	TEST_DATA_DIR_PATH = RESOURCE_DIR_PATH.joinpath(NameConst.TEST_DATA_DIR_NAME)

	# path list under fixtures directory
	BASE_FIXTURES_DIR_PATH = os.path.join(FIXTURES_DIR_PATH, NameConst.DEFAULT_FIXTURE_DIR_NAME)
	PROD_FIXTURES_DIR_PATH = os.path.join(FIXTURES_DIR_PATH, NameConst.PROD_FIXTURE_DIR_NAME)
	TEST_FIXTURES_DIR_PATH = os.path.join(FIXTURES_DIR_PATH, NameConst.TEST_FIXTURE_DIR_NAME)

	# compiled constants
	SYS_PATH_LIST = [
		BASE_DIR_PATH.__str__(), APP_DIR_PATH.__str__(),
		RESOURCE_DIR_PATH.__str__(), WRITABLE_DIR_PATH.__str__()
	]

	FIXTURE_DIRS_LIST = [BASE_FIXTURES_DIR_PATH, PROD_FIXTURES_DIR_PATH, TEST_FIXTURES_DIR_PATH]


__all__ = [
	"NameConst", "PathConst", "EnvDefaults", "MsbConfigNames",
]
