import { HttpClient , HttpStatusCode } from '@/data/protocols/http' ; import { RemoteSurveyResultModel } from '@/data/models' ; import { AccessDeniedError , UnexpectedError } from '@/domain/errors' ; import { LoadSurveyResult } from '@/domain/usecases' ; export class RemoteLoadSurveyResult implements LoadSurveyResult { constructor ( private readonly url , private readonly httpClient ) { } async load ( ) { const httpResponse = await this . httpClient . request ( { url : this . url , method : 'get' } ) ; const remoteSurveyResult = httpResponse . body ; switch ( httpResponse . statusCode ) { case HttpStatusCode . ok : return { ... remoteSurveyResult , date : new Date ( remoteSurveyResult . date ) } ; case HttpStatusCode . forbidden : throw new AccessDeniedError ( ) ; default : throw new UnexpectedError ( ) ; } } } export namespace RemoteLoadSurveyResult { export type Model = RemoteSurveyResultModel ; }