package migration

import "testing"

func TestBuildOnboardingHintsGoogleDWD(t *testing.T) {
	s := &Service{}
	h := s.BuildOnboardingHints(t.Context(), "user-id", Project{
		ID:             "p1",
		SourceProvider: "google",
		AuthMode:       AuthModeGoogleDWD,
		Status:         "active",
	}, Invite{Status: "claimed"})
	if h.NeedsUserOAuth {
		t.Fatal("google dwd should not need user oauth")
	}
	if h.WaitingForAdmin {
		t.Fatal("active project should not wait for admin")
	}
}

func TestBuildOnboardingHintsDraftProject(t *testing.T) {
	s := &Service{}
	h := s.BuildOnboardingHints(t.Context(), "", Project{
		ID:             "p1",
		SourceProvider: "google",
		AuthMode:       "oauth",
		Status:         "draft",
	}, Invite{Status: "claimed"})
	if !h.WaitingForAdmin || h.WaitingReason != "project_not_activated" {
		t.Fatalf("expected wait activate, got %#v", h)
	}
	if !h.NeedsUserOAuth {
		t.Fatal("oauth mode needs user oauth")
	}
}

func TestBuildOnboardingHintsMicrosoftConsent(t *testing.T) {
	s := &Service{}
	h := s.BuildOnboardingHints(t.Context(), "", Project{
		ID:             "p1",
		SourceProvider: "microsoft",
		AuthMode:       "oauth",
		Status:         "active",
	}, Invite{Status: "claimed"})
	if !h.NeedsMicrosoftAdminConsent {
		t.Fatal("expected ms admin consent hint")
	}
}

func TestBuildOnboardingHintsMicrosoftApp(t *testing.T) {
	s := &Service{}
	h := s.BuildOnboardingHints(t.Context(), "user-id", Project{
		ID:                      "p1",
		SourceProvider:          "microsoft",
		AuthMode:                AuthModeMicrosoftApp,
		Status:                  "active",
		MicrosoftAdminConsentAt: strPtr("2026-01-01T00:00:00Z"),
	}, Invite{Status: "claimed"})
	if h.NeedsUserOAuth {
		t.Fatal("microsoft app should not need user oauth")
	}
}

func strPtr(s string) *string { return &s }

func TestBuildInviteOnboardingHintsUnclaimed(t *testing.T) {
	s := &Service{}
	h := s.BuildInviteOnboardingHints(Project{
		SourceProvider: "google",
		AuthMode:       AuthModeGoogleDWD,
	}, Invite{Status: "invited"})
	if h.NeedsUserOAuth {
		t.Fatal("dwd invite should not prompt oauth before claim")
	}
}
