from typing import TypedDict

from graphon.variables.segments import Segment
from graphon.variables.types import SegmentType


class _VarTypedDict(TypedDict, total=False):
    value_type: SegmentType


def serialize_value_type(v: _VarTypedDict | Segment) -> str:
    if isinstance(v, Segment):
        return str(v.value_type.exposed_type())
    else:
        value_type = v.get("value_type")
        if value_type is None:
            raise ValueError("value_type is required but not provided")
        return str(value_type.exposed_type())
