from pathlib import Path

# Get the project root directory
PROJECT_ROOT = Path(__file__).parent.parent
BASE_PATH = PROJECT_ROOT / "data" / "storage"

STORAGE_TYPES = ["local", "s3", "adls", "blob"]

DB_JOB_CREATE_QUERY = '''CREATE TABLE IF NOT EXISTS JOB_STATUS (
    ROW_ID INTEGER PRIMARY KEY AUTOINCREMENT,
    JOB_ID TEXT NOT NULL,
    FILE_NAME TEXT NOT NULL,
    STATUS TEXT NOT NULL,
    ERROR_CODE TEXT,
    ERROR_DESC TEXT,
    CREATED_DATE TEXT NOT NULL,
    RUN_DATE TEXT NOT NULL,
    START_TIME TEXT DEFAULT CURRENT_TIMESTAMP,
    END_TIME TEXT DEFAULT CURRENT_TIMESTAMP,
    PROCESSING_TIME TEXT
)'''

DB_JOB_INSERT_QUERY = '''INSERT INTO JOB_STATUS (
    JOB_ID, FILE_NAME, STATUS, ERROR_CODE, ERROR_DESC, 
    CREATED_DATE, RUN_DATE, START_TIME, END_TIME, PROCESSING_TIME
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'''

DB_JOB_UPDATE_QUERY = '''UPDATE JOB_STATUS 
SET STATUS = ?, 
    ERROR_CODE = ?,
    ERROR_DESC = ?,
    END_TIME = ?, 
    PROCESSING_TIME = ? 
WHERE JOB_ID = ?'''

DB_JOB_FETCH_QUERY = '''SELECT * FROM JOB_STATUS WHERE JOB_ID = ?'''

DB_LOG_CREATE_QUERY = '''CREATE TABLE IF NOT EXISTS ERROR_LOGS (
    ROW_ID INTEGER PRIMARY KEY AUTOINCREMENT,
    JOB_ID TEXT NOT NULL,
    MODULE_NAME TEXT NOT NULL,
    SCRIPT_NAME TEXT NOT NULL,
    LINE_NO INTEGER NOT NULL,
    ERROR_DESC TEXT NOT NULL,
    ERROR_STACK_TRACE TEXT,
    ERROR_TIME TEXT DEFAULT CURRENT_TIMESTAMP
)'''

DB_LOG_INSERT_QUERY = '''INSERT INTO ERROR_LOGS (
    JOB_ID, MODULE_NAME, SCRIPT_NAME, LINE_NO, 
    ERROR_DESC, ERROR_STACK_TRACE, ERROR_TIME
) VALUES (?, ?, ?, ?, ?, ?, ?)'''

DB_LOG_FETCH_QUERY = '''SELECT * FROM ERROR_LOGS WHERE JOB_ID = ?'''