#!/usr/bin/env python3
"""Upload a log file from logs/ to OSS (manual folder, no MySQL).

Usage:
  python scripts/upload_logs_to_oss.py run_xxx.log

  # 从 Python 调用
  from scripts.upload_logs_to_oss import main
  oss_path = main("run_xxx.log")
"""

from __future__ import annotations

import sys
from pathlib import Path

_ROOT = Path(__file__).resolve().parents[1]
_LOGS_DIR = _ROOT / "logs"
if str(_ROOT) not in sys.path:
    sys.path.insert(0, str(_ROOT))

from supply_infra.config import get_infra_settings
from supply_infra.oss.client import OssClient


def main(filename: str) -> str:
    """Read ``logs/{filename}``, upload to OSS, return public OSS path."""
    local_path = _LOGS_DIR / Path(filename).name
    if not local_path.is_file():
        raise FileNotFoundError(f"Log file not found: {local_path}")

    settings = get_infra_settings()
    client = OssClient(settings, root_prefix=settings.aliyun_oss_manual_log_prefix)
    object_key = client.object_key(local_path.name)
    return client.upload_file(local_path, object_key)


if __name__ == "__main__":
    oss_path = main("run_generate_demand_agent_20260716_160355_8f751d0d.html")
    print(oss_path)
