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

class Store {
  @observable isLoading = false;

  @action
  async getContract(id, onSuccess) {
    try {
      this.isLoading = true;
      const response = await Api.getInstance().getContract(id);
      console.log(response);

      this.isLoading = false;
      if (response.kind === 'ok') {
        if (response.data.meta.errorCode === 200) {
          if (onSuccess) onSuccess(response.data.data);
        } else {
          Alert.alert('Thông báo', response.data.meta.errorMessage);
        }
      } else {
        Alert.alert('Thông báo', 'Có lỗi xảy ra. Vui lòng thử lại sau!');
      }
    } catch (error) {
      console.log(error);
    }
  }

  @action
  async getOtpSign(type) {
    try {
      const response = await Api.getInstance().getOtpSign(type);
      if (response.kind === 'ok') {
        if (response.data.meta.errorCode === 200) {
        } else {
          Alert.alert('Thông báo', response.data.meta.errorMessage);
        }
      } else {
        Alert.alert('Thông báo', 'Có lỗi xảy ra. Vui lòng thử lại sau!');
      }
    } catch (error) {
      console.log(error);
    }
  }

  @action
  async confirmContract(body, onSuccess) {
    try {
      this.isLoading = true;
      const response = await Api.getInstance().confirmContract(body);
      console.log(response);

      this.isLoading = false;
      if (response.kind === 'ok') {
        if (response.data.meta.errorCode === 200) {
          if (onSuccess) onSuccess(response.data.data);
        } else {
          Alert.alert('Thông báo', response.data.meta.errorMessage);
        }
      } else {
        Alert.alert('Thông báo', 'Có lỗi xảy ra. Vui lòng thử lại sau!');
      }
    } catch (error) {
      console.log(error);
    }
  }
}

const SignTimaStore = new Store();
export default SignTimaStore;
