'use strict';

class Data {
  constructor(data = {}) {
    this.fs = data.fs;
    this.api = data.api;
    this.org = data.org;
    this.service = data.service;
    this.instance = data.instance;
  }

  async seed(sourceInstanceName) {
    const content = await this.fs.readDataFile();

    const body = {
      source: 'file',
      content,
    };

    if (sourceInstanceName) {
      body.source = sourceInstanceName;
      delete body.content;
    }

    const options = {
      method: 'PUT',
      endpoint: `/orgs/${this.org.orgName}/services/${this.service.serviceName}/instances/${this.instance.instanceName}/seed`,
      body,
    };

    await this.api.request(options);
  }
}

module.exports = Data;
