import { Container as l } from "unstated";
import { z as o } from "zod";
import { Gdpr as i } from "@accelbyte/sdk-gdpr";
const a = o.enum(["MARKED", "MARK_IGNORED"]), n = {
  isFetchingDeletion: !1,
  errorFetchingDeletion: null,
  deletionMark: null,
  gdprDeletionStatus: null,
  isRequestingDeletion: !1,
  errorRequestingDeletion: null,
  isFetchingGdpr: !1,
  gdprDataRequestList: null,
  isRequestingGdpr: !1,
  errorGdpr: null
};
class c extends l {
  constructor(e) {
    super(), this.sdk = e, this.markForDeletion = () => {
      this.setState({
        deletionMark: a.Enum.MARKED
      });
    }, this.ignoreDeletionMark = () => {
      this.setState({
        deletionMark: a.Enum.MARK_IGNORED
      });
    }, this.clear = () => {
      this.setState(n);
    }, this.state = n;
  }
  async fetchGdprDeletionStatus(e) {
    if (!this.state.isFetchingDeletion)
      try {
        this.setState({ isFetchingDeletion: !0 });
        const t = await i.DataDeletionApi(this.sdk, { cache: !1 }).getDeletionsStatus_ByUserId(e);
        return this.setState({ gdprDeletionStatus: t }), t;
      } catch (t) {
        throw this.setState({ errorFetchingDeletion: t }), t;
      } finally {
        this.setState({ isFetchingDeletion: !1 });
      }
  }
  async deleteAccount(e, t) {
    if (!this.state.isRequestingDeletion)
      try {
        this.setState({
          isRequestingDeletion: !0,
          errorRequestingDeletion: null
        }), await i.DataDeletionApi(this.sdk).postDeletion_ByUserId(t, { password: e });
      } catch (s) {
        throw this.setState({ errorRequestingDeletion: s }), s;
      } finally {
        this.setState({ isRequestingDeletion: !1 });
      }
  }
  async cancelDeleteAccount(e) {
    if (!this.state.isRequestingDeletion)
      try {
        this.setState({
          isRequestingDeletion: !0,
          errorRequestingDeletion: null
        }), await i.DataDeletionApi(this.sdk).deleteDeletion_ByUserId(e);
      } catch (t) {
        throw this.setState({ errorRequestingDeletion: t }), t;
      } finally {
        this.setState({ isRequestingDeletion: !1 });
      }
  }
  async fetchGdprRequestDataList(e, t, s) {
    if (!this.state.isFetchingGdpr)
      try {
        this.setState({
          isFetchingGdpr: !0,
          gdprDataRequestList: null,
          errorGdpr: null
        });
        const r = await i.DataRetrievalApi(this.sdk).getRequests_ByUserId(e, { offset: t, limit: s });
        return this.setState({ gdprDataRequestList: r }), r;
      } catch (r) {
        throw this.setState({ errorGdpr: r }), r;
      } finally {
        this.setState({ isFetchingGdpr: !1 });
      }
  }
  async requestGdprData(e, t) {
    if (!this.state.isRequestingGdpr)
      try {
        this.setState({ isRequestingGdpr: !0, errorGdpr: null }), await i.DataRetrievalApi(this.sdk).postRequest_ByUserId(t, { password: e });
      } catch (s) {
        throw this.setState({ errorGdpr: s }), s;
      } finally {
        this.setState({ isRequestingGdpr: !1 });
      }
  }
  async cancelRequestGdprData(e, t) {
    try {
      this.setState({ isRequestingGdpr: !0, errorGdpr: null }), await i.DataRetrievalApi(this.sdk).deleteRequest_ByUserId_ByRequestDate(t, e);
    } catch (s) {
      throw this.setState({ errorGdpr: s }), s;
    } finally {
      this.setState({ isRequestingGdpr: !1 });
    }
  }
  async downloadGdprData(e, t, s) {
    try {
      return this.setState({ isRequestingGdpr: !0, errorGdpr: null }), await i.DataRetrievalApi(this.sdk).postGenerate_ByUserId_ByRequestDate(s, e, { password: t });
    } catch (r) {
      throw this.setState({ errorGdpr: r }), r;
    } finally {
      this.setState({ isRequestingGdpr: !1 });
    }
  }
}
export {
  c as GdprAppManager
};
