import {observable, action, computed} from 'mobx';

export default class Setting {
  @observable data = {};
  @observable isLoading = false;

  constructor(context) {
    this.http = context.http;
    this.context = context;
  }

  @action
  getAll() {
    this.isLoading = true;
    return this.http.get(`settings`).then(res => {
      this.data = res.value;
      this.isLoading = false;
      return res;
    });
  }

  @action
  put(data) {
    this.isLoading = true;
    return this.http.put(`settings`, data).then(res => {
      this.isLoading = false;
      this.getAll();
      return res;
    }).catch(err=>{
      throw err;
    });
  }

}
