import EventEmitter from "events"
import type { CloudUserInfo } from "@roo-code/types"

export interface AuthServiceEvents {
	"auth-state-changed": [
		data: {
			state: AuthState
			previousState: AuthState
		},
	]
	"user-info": [data: { userInfo: CloudUserInfo }]
}

export type AuthState = "initializing" | "logged-out" | "active-session" | "attempting-session" | "inactive-session"

export interface AuthService extends EventEmitter<AuthServiceEvents> {
	// Lifecycle
	initialize(): Promise<void>

	// Authentication methods
	login(): Promise<void>
	logout(): Promise<void>
	handleCallback(code: string | null, state: string | null, organizationId?: string | null): Promise<void>

	// State methods
	getState(): AuthState
	isAuthenticated(): boolean
	hasActiveSession(): boolean
	hasOrIsAcquiringActiveSession(): boolean

	// Token and user info
	getSessionToken(): string | undefined
	getUserInfo(): CloudUserInfo | null
	getStoredOrganizationId(): string | null
}
