from pathlib import Path
from audit_storage_agent.config import load_config
from audit_storage_agent.client import ERPClient
from audit_storage_agent.logger import setup_logger
from audit_storage_agent.storage_identity import ensure_storage_identity

base_dir = Path(__file__).resolve().parent
logger = setup_logger(base_dir)
config = load_config(str(base_dir / ".env"))
logger.info("Configuration loaded successfully")
logger.info("ERP_BASE_URL=%s", config.erp_base_url)
logger.info("NODE_CODE=%s", config.node_code)
logger.info("STORAGE_ROOT=%s", config.storage_root)
logger.info("TENANT_ID=%s", config.tenant_id or "-")
logger.info("BRANCH_ID=%s", config.branch_id or "-")
identity_path = ensure_storage_identity(config)
logger.info("Storage identity file verified: %s", identity_path)
client = ERPClient(config)
response = client.heartbeat({"status": "CONFIG_TEST", "storage_root": str(config.storage_root), "agent_version": "0.2.0"})
logger.info("ERP heartbeat test response: %s", response)
print("Configuration and ERP connection test completed successfully.")
