import FakerStatic from 'faker';

export interface LoginAttempt {
  readonly date: string;
  readonly remoteIP: string;
  readonly username: string;
  readonly password: string;
  readonly sshClientVersion: string;
  readonly connectionUUID: string;
}

export interface StatResult {
  name: string;
  count: number;
}

export interface ApiaryAPI {
  streamLoginAttempts(): ReadableStream<LoginAttempt>;
}

export function fakeAttempt(): LoginAttempt {
  return {
    date: FakerStatic.date.recent().toLocaleDateString(),
    remoteIP: FakerStatic.internet.ip(),
    username: FakerStatic.internet.userName(),
    password: FakerStatic.internet.password(),
    sshClientVersion: FakerStatic.lorem.words(2),
    connectionUUID: FakerStatic.datatype.uuid(),
  };
}

export function fakeAttemptStream(): EventSource {
  const es = new EventSource('/stream');
  return es;
}
