import { Container as n } from "unstated";
import { Platform as s } from "@accelbyte/sdk-platform";
const a = {
  isFetching: !1,
  paymentAccounts: null,
  error: null,
  isDeleting: !1,
  deleteSuccess: null,
  deleteError: null,
  paymentStationMessage: null
};
class o extends n {
  constructor(e) {
    super(), this.sdk = e, this.setPaymentStationMessage = (t) => {
      this.setState({ paymentStationMessage: t });
    }, this.state = a;
  }
  async getPaymentAccounts(e) {
    try {
      if (this.state.isFetching)
        return;
      await this.setState({ isFetching: !0, paymentAccounts: null, error: null });
      const t = await s.PaymentAccountApi(this.sdk).getPaymentAccounts_ByUserId(e);
      this.setState({ paymentAccounts: t });
    } catch (t) {
      throw await this.setState({ error: t }), t;
    } finally {
      await this.setState({ isFetching: !1 });
    }
  }
  async delete(e, t) {
    try {
      return this.state.isDeleting ? !1 : (await this.setState({ isDeleting: !0, deleteError: null }), await s.PaymentAccountApi(this.sdk).deletePaymentAccount_ByUserId_ByType_ById(e, t.type, t.id), await this.setState({ deleteSuccess: !0 }), !0);
    } catch (i) {
      return await this.setState({ deleteError: i, deleteSuccess: !1 }), !1;
    } finally {
      await this.setState({ isDeleting: !1 });
    }
  }
  clear() {
    this.setState(a);
  }
}
export {
  o as PaymentMethodsAppManager
};
