/**
 * Test users
 * Predefined test users for integration tests
 */

export interface TestUser {
  did: string;
  handle: string;
  avatar?: string;
}

// ============================================================================
// Predefined Test Users
// ============================================================================

export const ALICE: TestUser = {
  did: "did:plc:alice111111111111111111",
  handle: "alice.test",
  avatar: "https://example.com/alice.jpg",
};

export const BOB: TestUser = {
  did: "did:plc:bob2222222222222222222222",
  handle: "bob.test",
  avatar: "https://example.com/bob.jpg",
};

export const CAROL: TestUser = {
  did: "did:plc:carol33333333333333333333",
  handle: "carol.test",
  avatar: "https://example.com/carol.jpg",
};

export const DAVE: TestUser = {
  did: "did:plc:dave444444444444444444444",
  handle: "dave.test",
  avatar: "https://example.com/dave.jpg",
};

export const EVE: TestUser = {
  did: "did:plc:eve5555555555555555555555",
  handle: "eve.test",
  avatar: "https://example.com/eve.jpg",
};

export const FRANK: TestUser = {
  did: "did:plc:frank6666666666666666666",
  handle: "frank.test",
  avatar: "https://example.com/frank.jpg",
};

export const GRACE: TestUser = {
  did: "did:plc:grace7777777777777777777",
  handle: "grace.test",
  avatar: "https://example.com/grace.jpg",
};

// All test users as a list
export const ALL_TEST_USERS = [ALICE, BOB, CAROL, DAVE, EVE, FRANK, GRACE];

// Maps for lookups
export const handleToDid = new Map<string, string>(ALL_TEST_USERS.map((u) => [u.handle, u.did]));

export const didToHandle = new Map<string, string>(ALL_TEST_USERS.map((u) => [u.did, u.handle]));

export const didToUser = new Map<string, TestUser>(ALL_TEST_USERS.map((u) => [u.did, u]));

// ============================================================================
// Current User State
// ============================================================================

let currentUser: TestUser | null = null;

/**
 * Set the current logged-in user for tests
 */
export function setCurrentUser(user: TestUser | null): void {
  currentUser = user;
}

/**
 * Get the current logged-in user
 */
export function getCurrentTestUser(): TestUser | null {
  return currentUser;
}

/**
 * Get the current user's DID, or null if not logged in
 */
export function getCurrentTestDid(): string | null {
  return currentUser?.did ?? null;
}

/**
 * Reset current user (call in beforeEach)
 */
export function resetCurrentUser(): void {
  currentUser = null;
}

// ============================================================================
// Identity Resolver Helpers
// ============================================================================

/**
 * Resolve a handle to DID (for mocking IdResolver)
 */
export function resolveHandle(handle: string): string | null {
  return handleToDid.get(handle) ?? null;
}

/**
 * Resolve a DID to handle (for mocking IdResolver)
 */
export function resolveDid(did: string): string | null {
  return didToHandle.get(did) ?? null;
}

/**
 * Get a user's avatar URL
 */
export function getAvatar(did: string): string | undefined {
  return didToUser.get(did)?.avatar;
}
