import { Resource } from 'rest-hooks';
import ICATPLUS from '../config/icat/icatPlus';
import { store } from '../store';

export default class ItemResource extends Resource {
  _id = undefined;
  name = '';
  type = '';
  description = '';
  comments = '';
  sampleId = undefined;

  pk() {
    return this._id?.toString();
  }

  static get key() {
    return 'ItemResource';
  }

  static url(params) {
    const { sessionId } = store.getState().user;
    const { investigationId, parcelId } = params;
    return `${ICATPLUS.server}/tracking/${sessionId}/investigation/id/${investigationId}/parcel/id/${parcelId}/item`;
  }

  static listUrl(params) {
    return this.url(params);
  }

  static deleteShape() {
    return {
      ...super.deleteShape(),
      fetch: (params, body) => this.fetch('delete', this.url(params), body),
    };
  }
}
