// Tiny fixture file used by the stub-bench scenarios.
// Skeleton-extractable structure (class + methods).
class AuthService {
  constructor(config) {
    this.config = config;
    this.tokenStore = new Map();
  }

  /** Authenticate a user against the upstream IDP. */
  async login(username, password) {
    if (!username || !password) throw new Error('missing credentials');
    const token = await this._mintToken(username);
    this.tokenStore.set(username, token);
    return { token, expiresIn: 3600 };
  }

  /** Verify a presented bearer token. */
  async verify(token) {
    for (const [user, stored] of this.tokenStore.entries()) {
      if (stored === token) return { valid: true, user };
    }
    return { valid: false };
  }

  /** Revoke a session by token. */
  async logout(token) {
    for (const [user, stored] of this.tokenStore.entries()) {
      if (stored === token) {
        this.tokenStore.delete(user);
        return true;
      }
    }
    return false;
  }

  async _mintToken(user) {
    return `tok-${user}-${Date.now()}`;
  }
}

module.exports = { AuthService };
