41 lines
1.3 KiB
Python
41 lines
1.3 KiB
Python
from __future__ import annotations
|
|
|
|
from typing import Dict
|
|
from .contracts import LocalProblem as CanonicalLocalProblem
|
|
|
|
class LocalProblem:
|
|
def __init__(self, asset_id: str, payload: Dict[str, object]):
|
|
self.asset_id = asset_id
|
|
self.payload = payload
|
|
|
|
|
|
class CatOptBridge:
|
|
@staticmethod
|
|
def to_canonical(lp: LocalProblem) -> Dict[str, object]:
|
|
return {"object_id": lp.asset_id, "payload": lp.payload}
|
|
|
|
@staticmethod
|
|
def from_canonical(data: Dict[str, object]) -> LocalProblem:
|
|
asset_id = str(data.get("object_id", "unknown"))
|
|
payload = dict(data.get("payload", {}))
|
|
# Return canonical LocalProblem type defined in core.contracts (tests shim)
|
|
return CanonicalLocalProblem(asset_id=asset_id, payload=payload)
|
|
|
|
# Minimal, standalone bridge API compatible with tests.
|
|
def to_canonical(lp):
|
|
return {
|
|
"type": "LocalProblem",
|
|
"object_id": lp.asset_id,
|
|
"data": lp.payload,
|
|
}
|
|
|
|
|
|
def from_canonical(data):
|
|
asset_id = str(data.get("object_id", "unknown"))
|
|
payload = dict(data.get("data", {}))
|
|
# Import the LocalProblem type from the tests contract shim to ensure
|
|
# consistency with test expectations
|
|
from .contracts import LocalProblem as CanonicalLocalProblem
|
|
|
|
return CanonicalLocalProblem(asset_id=asset_id, payload=payload)
|