from datetime import datetime

from pydantic import BaseModel, ConfigDict, Field, field_validator


class OemBrandingOut(BaseModel):
    model_config = ConfigDict(from_attributes=True)

    id: int
    user_id: int
    software_name: str = ""
    logo_path: str | None = None
    wechat: str | None = None
    qq: str | None = None
    wechat_qrcode: str | None = None
    qq_qrcode: str | None = None
    description: str | None = None
    created_at: datetime
    updated_at: datetime


class OemBrandingUpdate(BaseModel):
    """整表保存默认 OEM 品牌配置（允许置空图片与联系方式）。"""

    software_name: str = Field(default="", max_length=128)
    logo_path: str | None = None
    wechat: str | None = Field(default=None, max_length=128)
    qq: str | None = Field(default=None, max_length=128)
    wechat_qrcode: str | None = None
    qq_qrcode: str | None = None

    @field_validator("software_name")
    @classmethod
    def strip_software_name(cls, value: str) -> str:
        return value.strip()

    @field_validator("wechat", "qq")
    @classmethod
    def strip_optional_text(cls, value: str | None) -> str | None:
        if value is None:
            return None
        stripped = value.strip()
        return stripped or None

    @field_validator("logo_path", "wechat_qrcode", "qq_qrcode")
    @classmethod
    def normalize_image_value(cls, value: str | None) -> str | None:
        if value is None:
            return None
        stripped = value.strip()
        return stripped or None
