"""
One-time setup: verifies the Google Sheet is accessible and ensures all three
required tabs exist with correct header rows.

Run this once before the first scheduled scrape:
    python setup.py
"""

import os
import sys
import yaml
from pathlib import Path

from dotenv import load_dotenv

load_dotenv()

ROOT = Path(__file__).parent
config = yaml.safe_load((ROOT / "config.yaml").read_text())

spreadsheet_id = (
    os.environ.get("SPREADSHEET_ID")
    or config["storage"]["spreadsheet_id"]
)

if not spreadsheet_id:
    print("ERROR: SPREADSHEET_ID not found in env or config.yaml")
    sys.exit(1)

print(f"Connecting to spreadsheet: {spreadsheet_id}")

from storage.sheets_sync import SheetSync

sync = SheetSync(spreadsheet_id)

print("\nSetup complete. Tabs verified / created:")
print("  - Raw Pricing Data")
print("  - Changes Log")
print("  - AI Summaries")
print(
    "\nNext steps:\n"
    "  1. Make sure .env has GEMINI_API_KEY and Google credentials set\n"
    "  2. Run a test scrape: python -m scraper.main\n"
    "  3. Push to GitHub and add secrets:\n"
    "       GEMINI_API_KEY\n"
    "       SPREADSHEET_ID\n"
    "       GOOGLE_SERVICE_ACCOUNT_JSON_CONTENT\n"
    "     (paste the full contents of your service account JSON as a secret)"
)
