//@ts-nocheck
import { makeAutoObservable } from "mobx"
import { Api } from '../../services/api';
import { Alert } from "react-native";
class Store {
    isLoading = false

    constructor() {
        makeAutoObservable(this)
    }

    async addNfcData(body: any, onSuccess?: Function, onError?: Function) {
        this.isLoading = true
        try {
            const response = await Api.getInstance().addNfcData(body)
            this.isLoading = false
            if (response.kind === "ok") {
                if (response.data.meta.errorCode === 200) {
                    if (onSuccess) onSuccess()
                } else {
                    Alert.alert("Thông báo", response.data.meta?.errorMessage)
                    if (onError) onError()
                }
            } else {
                Alert.alert("Thông báo", "Có lỗi xảy ra. Vui lòng thử lại sau")
                if (onError) onError()
            }
        } catch (error) {
            console.log(error)
            this.isLoading = false
        }
    }
}

const nfcStore = new Store()
export default nfcStore