import json

import jingrow


@jingrow.whitelist()
def get_onboarding_status():
	onboarding_status = jingrow.db.get_value("User", jingrow.session.user, "onboarding_status")
	return jingrow.parse_json(onboarding_status) if onboarding_status else {}


@jingrow.whitelist()
def update_user_onboarding_status(steps: str, appName: str):
	steps = json.loads(steps)

	# get the current onboarding status
	onboarding_status = jingrow.db.get_value("User", jingrow.session.user, "onboarding_status")
	onboarding_status = jingrow.parse_json(onboarding_status)

	# update the onboarding status
	onboarding_status[appName + "_onboarding_status"] = steps

	jingrow.db.set_value(
		"User", jingrow.session.user, "onboarding_status", json.dumps(onboarding_status), update_modified=False
	)
