import { Injectable } from '@angular/core';
import { ConfigService } from '@shared/config/config.service';
import { HttpClient } from '@angular/common/http';
import { FleioApiService } from '@fleio-api/fleio-api.service';
import { IObjectModel } from '../model/object.model';
import { FleioId } from '@fleio-api/base-model/base-fleio-object.model';
import { Observable } from 'rxjs/internal/Observable';

@Injectable({
  providedIn: 'root',
})
export class ObjectsApiService extends FleioApiService<IObjectModel> {
  constructor(protected httpClient: HttpClient, protected config: ConfigService) {
    super();
    this.setEndpoint(config.getPanelApiUrl('openstack/object-store-objects'));
  }

  metadata(objectId: FleioId): Observable<Record<string, any>> {
    return this.getAction('metadata', {object_id: objectId});
  }

  delete(objectId: FleioId) {
    return this.postAction('delete', {
      object_id: objectId,
    });
  }

  copy(objectId: FleioId, destination: string) {
    return this.postAction('copy', {
      object_id: objectId,
      destination,
    });
  }
}
