from __future__ import annotations

import json
from http import HTTPStatus


class PoolRoutesMixin:
    def save_reason(self) -> None:
        try:
            body = self.read_json_body()
            self.application_service.save_reason(
                str(body.get("trade_date") or ""),
                str(body.get("code") or ""),
                str(body.get("reason") or ""),
            )
            self.send_json({"ok": True})
        except (ValueError, json.JSONDecodeError) as exc:
            self.send_json({"error": str(exc)}, HTTPStatus.BAD_REQUEST)
