// backend/src/services/SessionService.ts
import { v4 as uuidv4 } from 'uuid';

interface Session {
  id: string;
  isAuthenticated: boolean;
  createdAt: Date;
}

const sessions = new Map<string, Session>();

export class SessionService {
  public static createSession(): Session {
    const id = uuidv4();
    const newSession: Session = {
      id,
      isAuthenticated: false,
      createdAt: new Date(),
    };
    sessions.set(id, newSession);
    return newSession;
  }

  public static getSession(id: string): Session | undefined {
    return sessions.get(id);
  }

  public static authenticateSession(id: string): boolean {
    const session = sessions.get(id);
    if (session) {
      session.isAuthenticated = true;
      sessions.set(id, session);
      return true;
    }
    return false;
  }

  public static destroySession(id: string): void {
    sessions.delete(id);
  }
}
