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

import { ImageResp, ImageReq } from '../models/Image';

import { BaseService } from './base.service';

@Injectable()
export class ImageService extends BaseService {
  constructor(private http: HttpClient) {
    super();
  }

  public getListOfImages(): Observable<Array<ImageResp>> {
    return this.http.get<Array<ImageResp>>(`${this.apiUrl}/Image`, {
      headers: this.headers,
    });
  }

  public AddImage(commentImg: string, dataImg: string) {
    const bodyNewImage: ImageReq = {
      id: 0,
      comment: commentImg,
      data: dataImg,
    };

    return this.http.post(`${this.apiUrl}/Image`, 
                          bodyNewImage, 
                          { headers: this.headers });
  }
}
