name: Scheduled Cleanup
on:
  schedule:
    - cron: '0 0 * * 0' # Every Sunday at 00:00

jobs:
  cleanup:
    runs-on: macos-arm64
    steps:
      - name: Checkout
        uses: actions/checkout@v3
      
      - name: Clean test databases
        run: |
          find data/users -name "test_*.sqlite" -type f -delete || true
          echo "Cleaned test databases"
      
      - name: Clean cache tmp files
        run: |
          find data/cache -name "*.tmp" -type f -delete || true
          echo "Cleaned cache tmp files"
      
      - name: Clean log files
        run: |
          find . -name "*.log" -type f -delete || true
          find . -name "*.tmp" -type f -delete || true
          echo "Cleaned log/tmp files"
      
      - name: Summary
        run: |
          echo "::summary::Cleanup completed at $(date)"
          remaining=$(ls data/users/*.sqlite 2>/dev/null | grep -v test_ | wc -l || echo 0)
          echo "Remaining production databases: $remaining"