import {
put as e,
all as a,
call as t,
select as i,
takeLatest as d,
fork as g,
take as o,
} from "redux-saga/effects"
import {
lockDebug as l,
unlockDebug as r,
toggleDebug as u,
toggleOffline as y,
toggleSuspendCmd as c,
setDebugFlags as p,
fetchDebugFlags as s,
updateDebugFlag as f,
getIsSuspended as n,
getIsDebugUnlocked as S,
getIsOffline as m,
setSuspended as b,
setSuspendDisabled as D,
startAudit as h,
setAuditReport as F,
setAuditError as x,
setStartAudit as A,
upgradePrivateProfile as O,
setLocalDbCompacting as P,
startLocalDbCompact as k,
setLocalDbCompactSuccess as C,
setLocalDbCompactError as L,
} from "./debug.reducer"
import { uiAutomationSaga as B } from "./ui-automation.saga"
import { DEBUG_OFFLINE_FLAGS as v } from "./debug.constants"
import { getCoreBackend as I } from "../../backend"
import { apiCall as M } from "../../api/core"
import { taskErrorSaga as N } from "../error"
import { unlockStats as R } from "../stats"
import { getMyIdentity as T } from "../identity"
export function* fetchDebugFlagsSaga() {
try {
const a = I(),
t = yield M(a.getDebugFlags)
yield e(p(t))
} catch (e) {
yield N("fetchDebugFlagsSaga", e)
}
}
export function* toggleOfflineSaga() {
try {
const e = I(),
d = yield i(m),
g = v
;(yield a(g.map((a) => M(e.updateDebugFlag, a, !d))), yield t(fetchDebugFlagsSaga))
} catch (e) {
yield N("toggleOfflineSaga", e)
}
}
export function* suspendSaga() {
try {
const a = I()
for (;;)
(yield o(c),
yield e(D(!0)),
(yield i(n)) ? (yield M(a.resume), yield e(b(!1))) : (yield M(a.suspend), yield e(b(!0))),
yield e(D(!1)))
} catch (e) {
yield N("toggleSuspendSaga", e)
}
}
export function* toggleDebugSaga() {
;(yield i(S)) ? yield e(l()) : yield e(r())
}
export function* updateDebugFlagSaga({ payload: e }) {
try {
const { key: a, value: i } = e,
d = I()
;(yield M(d.updateDebugFlag, a, i), yield t(fetchDebugFlagsSaga))
} catch (e) {
yield N("updateDebugFlagSaga", e)
}
}
export function* startAuditSaga() {
try {
const a = I()
yield e(A())
const t = yield M(a.audit)
let i = 0,
d = 0,
g = 0
for (const { audit: e } of t)
(e.droppedBits || e.droppedBlocks || e.droppedTreeNodes || e.corrupt) &&
((i += 1), e.corrupt ? (g += 1) : (d += 1))
yield e(F({ report: t, issues: i, dropped: d, corrupt: g }))
} catch (a) {
;(yield e(x(a.message)), yield N("startAuditSaga", a))
}
}
export function* startLocalDbCompactSaga() {
try {
const a = I()
;(yield e(P()), yield M(a.compact), yield e(C()))
} catch (a) {
;(yield e(L(a.message)), yield N("compactSaga", a))
}
}
export function* upgradeProfileSaga() {
try {
const e = I(),
a = yield i(T)
if (!a) return
yield t(e.upgradeRoom, a.profileId)
} catch (e) {
yield N("upgradeProfileSaga", e)
}
}
export function* debugMobileSaga() {
;(yield g(suspendSaga),
yield d(s, fetchDebugFlagsSaga),
yield d(f, updateDebugFlagSaga),
yield d(y, toggleOfflineSaga),
yield d(h, startAuditSaga),
yield d(k, startLocalDbCompactSaga),
yield d(O, upgradeProfileSaga))
}
export function* debugSaga() {
;(yield g(suspendSaga),
yield d(h, startAuditSaga),
yield d(k, startLocalDbCompactSaga),
yield d(u, toggleDebugSaga),
yield d(y, toggleOfflineSaga),
yield d(r, B),
yield d(O, upgradeProfileSaga),
yield d(f, updateDebugFlagSaga),
yield d([R, s], fetchDebugFlagsSaga))
}