export module Interfaces { export interface LoggerInterface { debug(message); error(message); } export interface ApiConnectorInterface { execute(endpointPath: string, data: any): Promise; } export interface ClientInterface { id: string; coefficient: number; status: boolean; name: string; photo: string; payedTime: number; timeToPay: number; conversations: { [id: string]: ConversationInterface } send(event: string, data: {}); addSocket(socket: SocketIO.Socket); sendMessage(messageData); } export interface ClientsManagerInterface { get(id: string): Promise add(socket: SocketIO.Socket, data); } export interface ConversationsManagerInterface { get(id: string): Promise; add(conversation: ConversationInterface); remove(id: string); create(initiator: ClientInterface, recipient: ClientInterface): Promise; } export interface ConversationInterface { id: string; duration: number; state: ConversationState; getInitiator(): ClientInterface; getRecipient(): ClientInterface; newMessage(message, from, to); } export class ConversationState { private value; private constructor(state) { if (ConversationState.availableStates().indexOf(state) < 0) { throw new Error(`State "${state}" is not valid value`); } this.value = state; } toString() { return this.value; } public isEqualsTo(state: ConversationState) { return this.value === state.value; } static create(state) { return new ConversationState(state); } private static availableStates() { return ['init', 'running', 'stopped', 'paused']; } static INIT() { return ConversationState.create('init'); } static RUNNING() { return ConversationState.create('running'); } static STOPPED() { return ConversationState.create('stopped'); } static PAUSED() { return ConversationState.create('paused'); } } export class AppMode { private value; private constructor(mode) { this.value = mode; } toString() { return this.value; } public isEqualsTo(mode: AppMode) { return this.value === mode.value; } static create(mode) { if (AppMode.availableModes().indexOf(mode) < 0) { throw new Error(`Mode "${mode}" is not valid value`); } return new AppMode(mode); } private static availableModes() { return ['dev', 'prod']; } static DEV() { return AppMode.create('dev'); } static PROD() { return AppMode.create('prod'); } } }