from __future__ import annotations

from dataclasses import dataclass


@dataclass(slots=True, frozen=True)
class DartListItemDto:
    corp_cls: str
    corp_code: str
    corp_name: str
    stock_code: str
    report_nm: str
    rcept_no: str
    flr_nm: str | None = None
    rcept_dt: str | None = None

    @classmethod
    def from_dict(cls, data: dict[str, object]) -> "DartListItemDto":
        return cls(
            corp_cls=str(data.get("corp_cls", "")),
            corp_code=str(data.get("corp_code", "")),
            corp_name=str(data.get("corp_name", "")),
            stock_code=str(data.get("stock_code", "")),
            report_nm=str(data.get("report_nm", "")),
            rcept_no=str(data.get("rcept_no", "")),
            flr_nm=_opt_str(data.get("flr_nm")),
            rcept_dt=_opt_str(data.get("rcept_dt")),
        )


def _opt_str(value: object) -> str | None:
    if value is None:
        return None
    text = str(value)
    return text if text != "" else None
