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

export class PlaceStore {
  @observable provinces = [];
  @observable cities = [];
  @observable districts = [];
  @observable subdistricts = [];

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

  @action
  getAllProvince() {
    return this.http.get("places/provinces")
      .then(res => {
        this.provinces = res;
      });
  }

  @action
  getCitiesByProvince(provinceId) {
    return this.http.get(`places/city?province_id=${provinceId}`)
      .then(res => {
        this.cities = res;
      });
  }

  @action
  getDistrictByCity(cityId) {
    return this.http.get(`places/district?city_id=${cityId}`)
      .then(res => {
        this.districts = res;
      });
  }

  @action
  getSubdistrictByDistrict(districtId) {
    return this.http.get(`places/subdistrict?district_id=${districtId}`)
      .then(res => {
        this.subdistricts = res;
      });
  }
}
