import os

# METAMORF PROPERTIES
VERSION = "0.4.4.1"

# Constants for QUERY TYPES
QUERY_TYPE_INSERT = 0
QUERY_TYPE_UPDATE = 1
QUERY_TYPE_VIEW = 2
QUERY_TYPE_DELETE = 3
QUERY_TYPE_SELECT = 4
QUERY_TYPE_MERGE = 5
QUERY_TYPE_TRUNCATE_AND_INSERT = 6
# Query types for the engines
QUERY_TYPE_VALUES = 99


# Constants for JOIN TYPES
JOIN_TYPE_INNER = 0
JOIN_TYPE_MASTER = 1
JOIN_TYPE_DETAIL = 2
JOIN_TYPE_OUTER = 3

# Constants for FILES TYPES EXTENSIONS
FILE_TYPE_YML = "yml"
FILE_TYPE_SQL = "sql"
FILE_TYPE_LOG = "log"
FILE_TYPE_TXT = "txt"
FILE_TYPE_CSV = "csv"
FILE_TYPE_JSON = "json"

# Constants for CONNECTION TYPES
CONNECTION_SQLITE = "SQLITE"
CONNECTION_MYSQL = "MYSQL"
CONNECTION_SNOWFLAKE = "SNOWFLAKE"
CONNECTION_FIREBIRD = "FIREBIRD"
CONNECTION_POSTGRESQL = "POSTGRESQL"

CONNECTIONS_WITHOUT_OUTER_JOIN = [CONNECTION_SQLITE, CONNECTION_MYSQL]

# Constants for ENGINES
MODULE_ELT = "ELT"
MODULE_DV = "DATAVAULT"

# Constants for Configuration Location
LOG_FILE_NAME = "metamorf"
CONFIGURATION_FILE_PATH = "configuration"
CONFIGURATION_FILE_NAME = 'configuration.yml'
CONFIGURATION_FILE_DATA = 'configuration_data_'
CONFIGURATION_FILE_METADATA = 'configuration_metadata_'
PROPERTIES_FILE_PATH = "configuration"
PROPERTIES_FILE_NAME = 'properties.yml'
INITIALIZATION_FILE_PATH = "initialization"
INITIALIZATION_FILE_NAME = 'init_'
ENTRY_FILES_PATH = "entry"
OUTPUT_FILES_PATH = 'output'
BACKUP_FILES_PATH = 'backup'
ACTUAL_PATH = os.getcwd()
PACKAGE_PATH = os.path.dirname(__file__)

# FILE WRITER
FILE_WRITER_NEW_FILE = "w"
FILE_WRITER_APPEND = "a"

# LOG System
LOG_LEVEL_ONLY_LOG = 7
LOG_LEVEL_CRITICAL = 6
LOG_LEVEL_ERROR = 5
LOG_LEVEL_WARNING = 4
LOG_LEVEL_OK = 3
LOG_LEVEL_INFO = 2
LOG_LEVEL_DEBUG = 1

# Colors
COLOR_DEFAULT = "\033[0m"
COLOR_BLACK = "\033[0;30m"
COLOR_RED = "\033[0;31m"
COLOR_GREEN = "\033[0;32m"
COLOR_BROWN = "\033[0;33m"
COLOR_BLUE = "\033[0;34m"
COLOR_PURPLE = "\033[0;35m"
COLOR_CYAN = "\033[0;36m"
COLOR_LIGHT_GRAY = "\033[0;37m"
COLOR_DARK_GRAY = "\033[1;30m"
COLOR_LIGHT_RED = "\033[1;31m"
COLOR_LIGHT_GREEN = "\033[1;32m"
COLOR_YELLOW = "\033[1;33m"
COLOR_LIGHT_BLUE = "\033[1;34m"
COLOR_LIGHT_PURPLE = "\033[1;35m"
COLOR_LIGHT_CYAN = "\033[1;36m"
COLOR_LIGHT_WHITE = "\033[1;37m"

# ENTRY FILES
FILE_ENTRY_AGGREGATORS = 'ENTRY_AGGREGATORS'
FILE_ENTRY_DATASET_MAPPINGS = 'ENTRY_DATASET_MAPPINGS'
FILE_ENTRY_DATASET_RELATIONSHIPS = 'ENTRY_DATASET_RELATIONSHIPS'
FILE_ENTRY_ENTITY = 'ENTRY_ENTITY'
FILE_ENTRY_FILTERS = 'ENTRY_FILTERS'
FILE_ENTRY_ORDER = 'ENTRY_ORDER'
FILE_ENTRY_PATH = 'ENTRY_PATH'
FILE_ENTRY_HAVING = 'ENTRY_HAVING'
FILE_ENTRY_DV_ENTITY = 'ENTRY_DV_ENTITY'
FILE_ENTRY_DV_MAPPINGS = 'ENTRY_DV_MAPPINGS'
FILE_ENTRY_DV_PROPERTIES = 'ENTRY_DV_PROPERTIES'
FILE_ENTRY_FILES = 'ENTRY_FILES'

# MANIFEST FILE
FILE_MANIFEST = 'manifest'

# TABLES
TABLE_ENTRY_AGGREGATORS = 'ENTRY_AGGREGATORS'
TABLE_ENTRY_DATASET_MAPPINGS = 'ENTRY_DATASET_MAPPINGS'
TABLE_ENTRY_DATASET_RELATIONSHIPS = 'ENTRY_DATASET_RELATIONSHIPS'
TABLE_ENTRY_ENTITY = 'ENTRY_ENTITY'
TABLE_ENTRY_FILTERS = 'ENTRY_FILTERS'
TABLE_ENTRY_HAVING = 'ENTRY_HAVING'
TABLE_ENTRY_ORDER = 'ENTRY_ORDER'
TABLE_ENTRY_PATH = 'ENTRY_PATH'
TABLE_ENTRY_DV_MAPPINGS = 'ENTRY_DV_MAPPINGS'
TABLE_ENTRY_DV_ENTITY = 'ENTRY_DV_ENTITY'
TABLE_ENTRY_DV_PROPERTIES = 'ENTRY_DV_PROPERTIES'
TABLE_ENTRY_FILES = 'ENTRY_FILES'
TABLE_OM_DATASET = 'OM_DATASET'
TABLE_OM_DATASET_EXECUTION = 'OM_DATASET_EXECUTION'
TABLE_OM_DATASET_T_ORDER = 'OM_DATASET_T_ORDER'
TABLE_OM_DATASET_T_AGG = 'OM_DATASET_T_AGG'
TABLE_OM_DATASET_T_DISTINCT = 'OM_DATASET_T_DISTINCT'
TABLE_OM_DATASET_SPECIFICATION = 'OM_DATASET_SPECIFICATION'
TABLE_OM_DATASET_RELATIONSHIPS = 'OM_DATASET_RELATIONSHIPS'
TABLE_OM_DATASET_T_MAPPING = 'OM_DATASET_T_MAPPING'
TABLE_OM_DATASET_T_FILTER = 'OM_DATASET_T_FILTER'
TABLE_OM_DATASET_T_HAVING = 'OM_DATASET_T_HAVING'
TABLE_OM_DATASET_PATH = 'OM_DATASET_PATH'
TABLE_OM_PROPERTIES = 'OM_PROPERTIES'
TABLE_OM_DATASET_HARDCODED = 'OM_DATASET_HARDCODED'
TABLE_OM_DATASET_DV = 'OM_DATASET_DV'
TABLE_OM_DATASET_FILE = 'OM_DATASET_FILE'
TABLE_OM_REF_QUERY_TYPE = 'OM_REF_QUERY_TYPE'
TABLE_OM_REF_KEY_TYPE = 'OM_REF_KEY_TYPE'
TABLE_OM_REF_ENTITY_TYPE = 'OM_REF_ENTITY_TYPE'
TABLE_OM_REF_JOIN_TYPE = 'OM_REF_JOIN_TYPE'
TABLE_OM_REF_MODULES = 'OM_REF_MODULES'
TABLE_OM_REF_ORDER_TYPE = 'OM_REF_ORDER_TYPE'

# TABLES GIT
TABLE_GIT_ENTRY_AGGREGATORS = 'GIT_ENTRY_AGGREGATORS'
TABLE_GIT_ENTRY_DATASET_MAPPINGS = 'GIT_ENTRY_DATASET_MAPPINGS'
TABLE_GIT_ENTRY_DATASET_RELATIONSHIPS = 'GIT_ENTRY_DATASET_RELATIONSHIPS'
TABLE_GIT_ENTRY_ENTITY = 'GIT_ENTRY_ENTITY'
TABLE_GIT_ENTRY_FILTERS = 'GIT_ENTRY_FILTERS'
TABLE_GIT_ENTRY_HAVING = 'GIT_ENTRY_HAVING'
TABLE_GIT_ENTRY_ORDER = 'GIT_ENTRY_ORDER'
TABLE_GIT_ENTRY_PATH = 'GIT_ENTRY_PATH'
TABLE_GIT_ENTRY_DV_ENTITY = 'GIT_ENTRY_DV_ENTITY'
TABLE_GIT_ENTRY_DV_MAPPINGS = 'GIT_ENTRY_DV_MAPPINGS'
TABLE_GIT_ENTRY_DV_PROPERTIES = 'GIT_ENTRY_DV_PROPERTIES'
TABLE_GIT_ENTRY_FILES = 'GIT_ENTRY_FILES'

# TABLES IM
TABLE_IM_OM_DATASET_INFORMATION = "OM_DATASET_INFORMATION"
TABLE_IM_OM_RELATIONSHIPS = "OM_RELATIONSHIPS"
TABLE_IM_OM_DATASET_SPECIFICATION_INFORMATION = "OM_DATASET_SPECIFICATION_INFORMATION"

# COLUMNS METADATA
## Entry Metadata
COLUMNS_ENTRY_AGGREGATORS = ['COD_ENTITY_TARGET','COD_ENTITY_SOURCE', 'COLUMN_NAME', 'NUM_BRANCH', 'OWNER']
COLUMNS_ENTRY_ORDER = ['COD_ENTITY_TARGET','COD_ENTITY_SOURCE', 'COLUMN_NAME', 'NUM_BRANCH', 'ORDER_TYPE', 'OWNER']
COLUMNS_ENTRY_FILTERS = ['COD_ENTITY_TARGET', 'VALUE', 'NUM_BRANCH', 'OWNER']
COLUMNS_ENTRY_HAVING = ['COD_ENTITY_TARGET', 'VALUE', 'NUM_BRANCH', 'OWNER']
COLUMNS_ENTRY_PATH = ['COD_PATH', 'DATABASE_NAME', 'SCHEMA_NAME', 'OWNER']
COLUMNS_ENTRY_DATASET_RELATIONSHIPS = ['COD_ENTITY_MASTER', 'COLUMN_NAME_MASTER', 'COD_ENTITY_DETAIL', 'COLUMN_NAME_DETAIL', 'RELATIONSHIP_TYPE', 'OWNER']
COLUMNS_ENTRY_ENTITY = ['COD_ENTITY', 'TABLE_NAME', 'ENTITY_TYPE', 'COD_PATH', 'STRATEGY', 'OWNER']
COLUMNS_ENTRY_DATASET_MAPPINGS = ['COD_ENTITY_SOURCE', 'VALUE_SOURCE', 'COD_ENTITY_TARGET', 'COLUMN_NAME_TARGET', 'COLUMN_TYPE_TARGET','ORDINAL_POSITION','COLUMN_LENGTH','COLUMN_PRECISION', 'NUM_BRANCH', 'KEY_TYPE', 'SW_DISTINCT', 'OWNER']
COLUMN_ENTRY_OWNER = 'OWNER'
COLUMNS_ENTRY_DV_MAPPINGS = ['COD_ENTITY_SOURCE', 'COLUMN_NAME_SOURCE','COD_ENTITY_TARGET', 'COLUMN_NAME_TARGET', 'COLUMN_TYPE_TARGET', 'ORDINAL_POSITION', 'COLUMN_LENGTH', 'COLUMN_PRECISION', 'NUM_BRANCH', 'NUM_CONNECTION', 'KEY_TYPE', 'SATELLITE_NAME', 'ORIGIN_IS_INCREMENTAL', 'ORIGIN_IS_TOTAL', 'ORIGIN_IS_CDC', 'OWNER']
COLUMNS_ENTRY_DV_ENTITY = ['COD_ENTITY', 'ENTITY_NAME', 'ENTITY_TYPE','COD_PATH', 'NAME_STATUS_TRACKING_SATELLITE', 'NAME_RECORD_TRACKING_SATELLITE', 'NAME_EFFECTIVITY_SATELLITE', 'OWNER']
COLUMNS_ENTRY_DV_PROPERTIES = ['COD_ENTITY', 'NUM_CONNECTION', 'HASH_NAME', 'OWNER']
COLUMNS_ENTRY_FILES = ['COD_ENTITY', 'FILE_PATH', 'FILE_NAME', 'DELIMITER_CHARACTER', 'OWNER']
## Git tables
COLUMNS_GIT_ENTRY_AGGREGATORS = ['COD_ENTITY_TARGET','COD_ENTITY_SOURCE', 'COLUMN_NAME', 'NUM_BRANCH', 'OWNER']
COLUMNS_GIT_ENTRY_ORDER = ['COD_ENTITY_TARGET','COD_ENTITY_SOURCE', 'COLUMN_NAME', 'NUM_BRANCH', 'ORDER_TYPE', 'OWNER']
COLUMNS_GIT_ENTRY_FILTERS = ['COD_ENTITY_TARGET', 'VALUE', 'NUM_BRANCH', 'OWNER']
COLUMNS_GIT_ENTRY_HAVING = ['COD_ENTITY_TARGET', 'VALUE', 'NUM_BRANCH', 'OWNER']
COLUMNS_GIT_ENTRY_PATH = ['COD_PATH', 'DATABASE_NAME', 'SCHEMA_NAME', 'OWNER']
COLUMNS_GIT_ENTRY_DATASET_RELATIONSHIPS = ['COD_ENTITY_MASTER', 'COLUMN_NAME_MASTER', 'COD_ENTITY_DETAIL', 'COLUMN_NAME_DETAIL', 'RELATIONSHIP_TYPE', 'OWNER']
COLUMNS_GIT_ENTRY_ENTITY = ['COD_ENTITY', 'TABLE_NAME', 'ENTITY_TYPE', 'COD_PATH', 'STRATEGY', 'OWNER']
COLUMNS_GIT_ENTRY_DATASET_MAPPINGS = ['COD_ENTITY_SOURCE', 'VALUE_SOURCE', 'COD_ENTITY_TARGET', 'COLUMN_NAME_TARGET', 'COLUMN_TYPE_TARGET','ORDINAL_POSITION','COLUMN_LENGTH','COLUMN_PRECISION', 'NUM_BRANCH', 'KEY_TYPE', 'SW_DISTINCT', 'OWNER']
COLUMNS_GIT_ENTRY_DV_ENTITY = ['COD_ENTITY', 'ENTITY_NAME', 'ENTITY_TYPE', 'COD_PATH', 'NAME_STATUS_TRACKING_SATELLITE', 'NAME_RECORD_TRACKING_SATELLITE', 'NAME_EFFECTIVITY_SATELLITE', 'OWNER']
COLUMNS_GIT_ENTRY_DV_PROPERTIES = ['COD_ENTITY', 'NUM_CONNECTION', 'HASH_NAME', 'OWNER']
COLUMNS_GIT_ENTRY_DV_MAPPINGS = ['COD_ENTITY_SOURCE', 'COLUMN_NAME_SOURCE', 'COD_ENTITY_TARGET', 'COLUMN_NAME_TARGET', 'COLUMN_TYPE_TARGET', 'ORDINAL_POSITION', 'COLUMN_LENGTH', 'COLUMN_PRECISION', 'NUM_BRANCH', 'NUM_CONNECTION', 'KEY_TYPE', 'SATELLITE_NAME', 'ORIGIN_IS_INCREMENTAL', 'ORIGIN_IS_TOTAL', 'ORIGIN_IS_CDC', 'OWNER']
COLUMNS_GIT_ENTRY_FILES = ['COD_ENTITY', 'FILE_PATH',  'FILE_NAME', 'DELIMITER_CHARACTER', 'OWNER']
COLUMN_GIT_ENTRY_OWNER = 'OWNER'
## Reference Metadata
COLUMNS_OM_REF_ORDER_TYPE = ['ID_ORDER_TYPE', 'ORDER_TYPE_NAME', 'ORDER_TYPE_VALUE', 'ORDER_TYPE_DESCRIPTION']
COLUMNS_OM_REF_MODULES = ['ID_MODULE','MODULE_NAME','MODULE_FULL_NAME', 'MODULE_DESCRIPTION']
COLUMNS_OM_REF_JOIN_TYPE = ['ID_JOIN_TYPE', 'JOIN_NAME', 'JOIN_VALUE', 'JOIN_DESCRIPTION']
COLUMNS_OM_REF_ENTITY_TYPE = ['ID_ENTITY_TYPE', 'ENTITY_TYPE_NAME', 'ENTITY_TYPE_DESCRIPTION', 'ENTITY_TYPE_FULL_NAME', 'ID_MODULE']
COLUMNS_OM_REF_KEY_TYPE = ['ID_KEY_TYPE', 'KEY_TYPE_NAME', 'KEY_TYPE_DESCRIPTION']
COLUMNS_OM_REF_QUERY_TYPE = ['ID_QUERY_TYPE', 'QUERY_TYPE_NAME', 'QUERY_TYPE_DESCRIPTION']
## Metadata
COLUMNS_OM_DATASET = ['ID_DATASET', 'DATASET_NAME', 'ID_ENTITY_TYPE', 'ID_PATH' , 'META_OWNER', 'START_DATE', 'END_DATE']
COLUMNS_OM_DATASET_EXECUTION = ['ID_DATASET', 'ID_QUERY_TYPE','META_OWNER', 'START_DATE', 'END_DATE']
COLUMNS_OM_DATASET_T_ORDER = ['ID_T_ORDER', 'ID_DATASET', 'ID_BRANCH', 'ID_DATASET_SPEC', 'ID_ORDER_TYPE','META_OWNER', 'START_DATE', 'END_DATE']
COLUMNS_OM_DATASET_T_AGG = ['ID_T_AGG', 'ID_DATASET', 'ID_BRANCH', 'ID_DATASET_SPEC','META_OWNER', 'START_DATE', 'END_DATE']
COLUMNS_OM_DATASET_T_DISTINCT = ['ID_T_DISTINCT', 'ID_DATASET', 'ID_BRANCH', 'SW_DISTINCT','META_OWNER', 'START_DATE', 'END_DATE']
COLUMNS_OM_DATASET_SPECIFICATION = ['ID_DATASET_SPEC', 'ID_DATASET', 'ID_KEY_TYPE', 'COLUMN_NAME', 'COLUMN_TYPE', 'ORDINAL_POSITION', 'IS_NULLABLE', 'COLUMN_LENGTH', 'COLUMN_PRECISION', 'COLUMN_SCALE','META_OWNER', 'START_DATE', 'END_DATE']
COLUMNS_OM_DATASET_RELATIONSHIPS = ['ID_RELATIONSHIP', 'ID_DATASET_SPEC_MASTER', 'ID_DATASET_SPEC_DETAIL', 'ID_JOIN_TYPE','META_OWNER', 'START_DATE', 'END_DATE']
COLUMNS_OM_DATASET_T_MAPPING = ['ID_T_MAPPING', 'ID_BRANCH', 'ID_DATASET_SPEC', 'VALUE_MAPPING','META_OWNER', 'START_DATE', 'END_DATE']
COLUMNS_OM_DATASET_PATH = ['ID_PATH', 'DATABASE_NAME', 'SCHEMA_NAME','META_OWNER', 'START_DATE', 'END_DATE']
COLUMNS_OM_DATASET_T_FILTER = ['ID_T_FILTER', 'ID_DATASET', 'ID_BRANCH', 'VALUE_FILTER','META_OWNER', 'START_DATE', 'END_DATE']
COLUMNS_OM_DATASET_T_HAVING = ['ID_T_HAVING', 'ID_DATASET', 'ID_BRANCH', 'VALUE_HAVING','META_OWNER', 'START_DATE', 'END_DATE']
COLUMNS_OM_DATASET_HARDCODED = ['ID_DATASET_HARDCODED', 'ID_DATASET', 'ID_BRANCH', 'CONTENT','META_OWNER', 'START_DATE', 'END_DATE']
COLUMNS_OM_PROPERTIES = ['PROPERTY', 'VALUE', 'START_DATE']
COLUMNS_OM_DATASET_DV = ['ID_DATASET', 'ID_ENTITY_TYPE', 'META_OWNER', 'START_DATE', 'END_DATE']
COLUMNS_OM_DATASET_FILE = ['ID_DATASET', 'FILE_PATH', 'FILE_NAME', 'DELIMITER_CHARACTER', 'META_OWNER', 'START_DATE', 'END_DATE']
COLUMN_OM_OWNER = 'META_OWNER'
## Information Mart
COLUMNS_OM_DATASET_INFORMATION = ['META_OWNER','ENTITY_TYPE_FULL_NAME', 'ENTITY_TYPE_DESCRIPTION', 'MODULE_NAME', 'MODULE_FULL_NAME', 'MODULE_DESCRIPTION', 'DATASET_NAME', 'DATABASE_NAME', 'SCHEMA_NAME', 'QUERY_TYPE_NAME', 'QUERY_TYPE_DESCRIPTION', 'START_DATE']
COLUMNS_OM_RELATIONSHIPS = ['META_OWNER', 'MASTER_DATABASE_NAME', 'MASTER_SCHEMA_NAME', 'MASTER_DATASET_NAME', 'MASTER_COLUMN_NAME', 'DETAIL_DATABASE_NAME', 'DETAIL_SCHEMA_NAME', 'DETAIL_DATASET_NAME', 'DETAIL_COLUMN_NAME', 'START_DATE']
COLUMNS_OM_DATASET_SPECIFICATION_INFORMATION = ['META_OWNER', 'DATASET_NAME', 'COLUMN_NAME', 'COLUMN_TYPE', 'ORDINAL_POSITION', 'IS_NULLABLE', 'COLUMN_LENGTH', "COLUMN_PRECISION", "COLUMN_SCALE"]

# ENGINES
## Entities
ENTITY_SRC = "SRC"
ENTITY_TB = "TB"
ENTITY_WITH = "WITH"
ENTITY_VIEW = "VIEW"
ENTITY_HUB = "HUB"
ENTITY_LINK = "LINK"
ENTITY_SAT = "SAT"
ENTITY_STS = "STS"
ENTITY_RTS = "RTS"
ENTITY_SATE = "SATE"

## Key Types
KEY_TYPE_PRIMARY_KEY = "PK"
KEY_TYPE_NULL = "NULL"
KEY_TYPE_BUSINESS_KEY = "BK"
KEY_TYPE_SEQUENCE = "SEQ"
KEY_TYPE_FOREIGN_KEY = "FK"
KEY_TYPE_HASH_KEY = "HK"
KEY_TYPE_ATTRIBUTE = "AT"
KEY_TYPE_STATUS = "ST"
KEY_TYPE_DRIVENKEY = "DK"
KEY_TYPE_RECORD_SOURCE = "RS"
KEY_TYPE_TENANT = "TN"
KEY_TYPE_HASHDIFF = "HD"
KEY_TYPE_DEPENDENT_CHILD_KEY = "DCK"
KEY_TYPE_APPLIED_DATE = "AD"

## Status Nodes
NODE_STATUS_WAITING = "WAITING"
NODE_STATUS_RUNNING = "RUNNING"
NODE_STATUS_FINISHED_OK = "OK"
NODE_STATUS_FINISHED_NOK = "NOK"
NODE_STATUS_SKIP = "SKIP"

# OUTPUT
##Output Types
OUTPUT_TYPE_SQL = "sql"
OUTPUT_TYPE_DBT = "dbt"