# -*- coding: utf-8 -*- """Account status mark CLI commands.""" from db.accounts_repo import ( get_account_by_id, update_account_error, update_account_last_used, update_account_session_status, ) from service._svc_common import _err_json, _ok_json, _say from util.logging_config import get_skill_logger def cmd_account_mark_session(account_id: int, session_status: str) -> None: """account mark-session --session-status """ log = get_skill_logger() log.info("account_mark_session id=%s status=%s", account_id, session_status) valid_statuses = ("unknown", "likely_valid", "needs_login", "expired") if session_status not in valid_statuses: _say(_err_json("ERROR:CLI_BAD_ARGS", f"session_status 必须为 {valid_statuses} 之一。")) return acc = get_account_by_id(account_id) if not acc: _say(_err_json("ERROR:ACCOUNT_NOT_FOUND", f"账号 id={account_id} 不存在。")) return update_account_session_status(account_id, session_status) _say(_ok_json({"id": account_id, "session_status": session_status})) def cmd_account_mark_error(account_id: int, error_code: str, error_message: str) -> None: """account mark-error --code --message """ log = get_skill_logger() log.info("account_mark_error id=%s code=%s", account_id, error_code) acc = get_account_by_id(account_id) if not acc: _say(_err_json("ERROR:ACCOUNT_NOT_FOUND", f"账号 id={account_id} 不存在。")) return update_account_error(account_id, error_code, error_message) _say(_ok_json({"id": account_id, "error_code": error_code})) def cmd_account_mark_used(account_id: int) -> None: """account mark-used """ log = get_skill_logger() log.info("account_mark_used id=%s", account_id) acc = get_account_by_id(account_id) if not acc: _say(_err_json("ERROR:ACCOUNT_NOT_FOUND", f"账号 id={account_id} 不存在。")) return update_account_last_used(account_id) _say(_ok_json({"id": account_id, "marked": "used"}))