name: Resolve PR conflicts (AI)

run-name: >-
  Resolve PR conflicts${{ inputs.pr_number && format(' for #{0}', inputs.pr_number) || inputs.branch && format(' under {0}', inputs.branch) || format(' after {0}', github.event_name) }}

on:
  push:
    branches: ["**"]
  pull_request_target:
    types: [opened, reopened]
  schedule:
    - cron: "2,32 * * * *"
  workflow_dispatch:
    inputs:
      pr_number:
        description: "Exact PR to scan (takes precedence over branch); leave blank for a branch/all scan"
        required: false
        default: ""
        type: string
      branch:
        description: "PR base or head branch to scan; leave blank with no PR number to scan all"
        required: false
        default: ""
        type: string
      detector_handoff:
        description: "Internal trusted worker routing flag (leave false)"
        required: false
        default: false
        type: boolean
      manual_retry:
        description: "Internal explicit-retry routing flag (leave false)"
        required: false
        default: false
        type: boolean
      depth:
        description: "Internal stacked-PR cascade depth (leave at 0)"
        required: false
        default: "0"
        type: string
  repository_dispatch:
    types: [resolve-conflicts-cascade]

permissions:
  actions: write
  contents: write
  pull-requests: write
  issues: write

jobs:
  control-plane:
    uses: lopugit/thingtime/.github/workflows/resolve-pr-conflicts.yml@github-actions
    with:
      pr_number: ${{ inputs.pr_number || '' }}
      branch: ${{ inputs.branch || '' }}
      detector_handoff: ${{ inputs.detector_handoff || false }}
      manual_retry: ${{ inputs.manual_retry || false }}
      depth: ${{ inputs.depth || '0' }}
    secrets: inherit
