from __future__ import annotations
from dataclasses import dataclass
from pathlib import Path

ARTICLE_TYPES = ["life", "photo", "link", "quote", "tech"]


@dataclass
class Article:
    slug: str
    lang: str          # "it" | "en"
    path: Path
    frontmatter: dict
    has_translation: bool
    translation_path: Path | None

    @property
    def draft(self) -> bool:
        return bool(self.frontmatter.get("draft", False))

    @property
    def meta_type(self) -> str:
        return str(self.frontmatter.get("type", ""))

    @property
    def meta_tags(self) -> str:
        tags = self.frontmatter.get("tags", [])
        if isinstance(tags, list):
            return ", ".join(str(t) for t in tags)
        return str(tags) if tags else ""

    @property
    def meta_categories(self) -> str:
        cats = self.frontmatter.get("categories", [])
        if isinstance(cats, list):
            return ", ".join(str(c) for c in cats)
        return str(cats) if cats else ""

    @property
    def meta_date(self) -> str:
        raw = self.frontmatter.get("date", "")
        if not raw:
            return ""
        return str(raw)[:10]  # ISO date → "YYYY-MM-DD"
