from pathlib import Path
import os
import re
import oracledb
import json
import base64
import hashlib
from datetime import datetime
import requests
import textwrap
import unicodedata
from typing import Optional
from collections import deque
from config_loader import load_config

def chunk_hash(text: str) -> str:
    return hashlib.sha256(text.encode("utf-8")).hexdigest()

config = load_config()

# =========================
# Oracle Autonomous Configuration
# =========================
WALLET_PATH = config.wallet_path
DB_ALIAS = config.db_alias
USERNAME = config.username
PASSWORD = config.password
os.environ["TNS_ADMIN"] = WALLET_PATH

_pool = None

def get_pool():
    global _pool

    if _pool:
        return _pool

    _pool = oracledb.create_pool(
        user=USERNAME,
        password=PASSWORD,
        dsn=DB_ALIAS,
        config_dir=WALLET_PATH,
        wallet_location=WALLET_PATH,
        wallet_password=PASSWORD,
        min=2,
        max=8,
        increment=1
    )

    return _pool
