import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';

import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { NGXLogger } from 'ngx-logger';

import {
  decodeMailCount,
  MailCountResponse,
  decodePaymentCount,
  PaymentCountResponse
} from '../apis/api';

@Injectable({
  providedIn: 'root'
})
export class DaesangApiService {
  constructor(private httpClient: HttpClient) {}

  public retrieveMailCount(url: string): Observable<MailCountResponse> {
    return this.httpClient
      .get(url, { responseType: 'text' })
      .pipe(map(res => decodeMailCount(res)));
  }

  public retrievePaymentCount(url: string): Observable<PaymentCountResponse> {
    return this.httpClient
      .get(url, { responseType: 'text' })
      .pipe(map(res => decodePaymentCount(res)));
  }
}
