import {MFUserCandidate} from '@makeflow/gateway-shared';

import {APIService} from './api-service';

export class MakeflowService {
  constructor(private apiService: APIService) {}

  async listUserCandidates(
    username: string,
    password: string,
  ): Promise<MFUserCandidate[]> {
    return this.apiService.post('/api/makeflow/list-user-candidates', {
      username,
      password,
    });
  }

  async authenticate(
    username: string,
    password: string,
    userId: string,
  ): Promise<void> {
    await this.apiService.post('/api/makeflow/authenticate', {
      username,
      password,
      user: userId,
    });
  }

  async checkAuthentication(): Promise<void> {
    await this.apiService.post('/api/makeflow/check-authentication');
  }

  async previewAppDefinition(): Promise<object> {
    return this.apiService.post('/api/makeflow/preview-app-definition');
  }

  async publishApp(): Promise<void> {
    await this.apiService.post('/api/makeflow/publish-app');
  }
}
