import { HttpClient , HttpStatusCode } from '@/data/protocols/http' ; import { Authentication } from '@/domain/usecases' ; import { InvalidCredentialsError , UnexpectedError } from '@/domain/errors' ; export class RemoteAuthentication implements Authentication { constructor ( private readonly url , private readonly httpClient ) { } async auth ( params ) { const httpResponse = await this . httpClient . request ( { url : this . url , method : 'post' , body : params } ) ; switch ( httpResponse . statusCode ) { case HttpStatusCode . ok : return httpResponse . body ; case HttpStatusCode . unauthorized : throw new InvalidCredentialsError ( ) ; default : throw new UnexpectedError ( ) ; } } } export namespace RemoteAuthentication { export type Model = Authentication . Model ; }