name: Update AAGUIDs

on:
  schedule:
    - cron: "0 0 * * 1" # Runs every Monday at midnight
  workflow_dispatch: # Allows manual triggering of the workflow

permissions:
  contents: write
  pull-requests: write

jobs:
  update-aaguids:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Fetch JSON data
        run: |
          curl -o data.json https://raw.githubusercontent.com/pocket-id/passkey-aaguids/refs/heads/main/combined_aaguid.json

      - name: Process JSON data
        run: |
          mkdir -p backend/resources
          jq -c 'map_values(.name)' data.json > backend/resources/aaguids.json
          rm data.json

      - name: Create Pull Request
        uses: peter-evans/create-pull-request@v7
        with:
          commit-message: "chore: update AAGUIDs"
          title: "chore: update AAGUIDs"
          body: |
            This PR updates the AAGUIDs file with the latest data from the [passkey-aaguids](https://github.com/pocket-id/passkey-aaguids) repository.
          branch: update-aaguids
          base: main
          delete-branch: true
