//@ts-nocheck
import { action, observable } from 'mobx';
import { Alert } from 'react-native';
import { Api } from '../../services/api';

class Store {
  @observable isLoading = false;
  @observable data = [];

  @action
  async getSchedulePayment(id, onSuccess?, onError?) {
    this.isLoading = true;
    const response = await Api.getInstance().getPaymentSchedule(id);
    this.isLoading = false;
    if (response.kind === 'ok') {
      if (response.data.meta.errorCode === 200) {
        if (onSuccess) onSuccess(response.data.data);
        this.data = response.data.data;
      } else {
        Alert.alert('Thông báo', response.data.meta.errorMessage, [
          { text: 'Đồng ý' },
        ]);
        if (onError) onError();
      }
    } else {
      this.isLoading = false;
      if (onError) onError();
      Alert.alert('Thông báo', 'Có lỗi xảy ra. Vui lòng thử lại sau!');
    }
  }
}
const SchedulePaymentStore = new Store();
export default SchedulePaymentStore;
