package service

import (
	"testing"

	reposync "github.com/pingcap/agent-git-service/internal/sync"
	"github.com/pingcap/agent-git-service/internal/sync/canonical"
)

func TestRepositorySyncDependencyPhaseOrdersPRConversationAfterParent(t *testing.T) {
	record := canonical.NewRecord(canonical.TypeIssueComment, "1", "issue-comment:1", map[string]any{"body": "hello"})
	record.ParentType = canonical.TypePullRequest
	payload, err := record.Payload()
	if err != nil {
		t.Fatal(err)
	}
	commentPhase := repositorySyncDependencyPhase(reposync.PlannedItem{ObjectType: canonical.TypeIssueComment, Action: reposync.ActionCreate, Payload: payload})
	pullPhase := repositorySyncDependencyPhase(reposync.PlannedItem{ObjectType: canonical.TypePullRequest, Action: reposync.ActionCreate})
	reviewPhase := repositorySyncDependencyPhase(reposync.PlannedItem{ObjectType: canonical.TypePullRequestReview, Action: reposync.ActionCreate})
	if !(pullPhase < commentPhase && commentPhase < reviewPhase) {
		t.Fatalf("dependency phases pull=%d conversation=%d review=%d", pullPhase, commentPhase, reviewPhase)
	}
}
