"""
Script to analyze the Google Sheets data structure
This will help us understand the data format and fix filtering issues
"""

import gspread
from google.oauth2.credentials import Credentials
import pandas as pd
import json

# Read credentials from file
with open('credentials.json', 'r') as f:
    creds_info = json.load(f)

# Spreadsheet ID from the shared link
SPREADSHEET_ID = "1ayEGU0h_R7CY55COC1U94-p0rJch109YBGvezjYjHWw"

print("=" * 80)
print("ANALYZING GOOGLE SHEETS DATA")
print("=" * 80)

try:
    # Note: This will use service account or OAuth credentials
    # For now, let's just create a placeholder that shows what we need
    print("\nTo analyze your data, please run the Flask app and access the dashboard.")
    print("The debug output will now show:")
    print("  - Sample dates from your sheet")
    print("  - Unique years found")
    print("  - Total faturacao by year")
    print("  - Filtering details")
    print("\nPlease:")
    print("1. Restart your Flask app: python app.py")
    print("2. Access the dashboard and select year 2025")
    print("3. Check the terminal output for [DEBUG] messages")
    print("4. Share those debug messages with me")
    
except Exception as e:
    print(f"\nError: {e}")
    print("\nPlease run the Flask app and check the terminal output for [DEBUG] messages")

print("\n" + "=" * 80)
print("Alternatively, manually check your Google Sheet:")
print("=" * 80)
print("\n1. Open: https://docs.google.com/spreadsheets/d/1ayEGU0h_R7CY55COC1U94-p0rJch109YBGvezjYjHWw/edit")
print("\n2. Check the column named 'Mês' (or similar)")
print("   - What format are the dates? Examples:")
print("     • 2025/01 (year/month)")
print("     • 01/2025 (month/year)")
print("     • Jan/2025 (month name/year)")
print("     • 2025-01-15 (full date)")
print("\n3. For 2025 data:")
print("   - How many rows have 2025 in the date?")
print("   - What is the sum of all 'Faturacao' values for 2025?")
print("\n4. Check the second sheet (tab) - that's what the app uses")
print("   - The app reads from: spreadsheet.worksheets()[1]")
print("   - This is usually the second tab in your workbook")
