"""Pydantic v2 схемы для job_settings API."""

from datetime import datetime

from pydantic import BaseModel, Field


class JobSettingRead(BaseModel):
    job_type: str
    enabled: bool
    queue_name: str
    cron_schedule: str | None
    rate_ms: int | None
    max_retries: int
    max_concurrency: int
    extra_config: dict
    updated_at: datetime
    updated_by: str | None
    description: str | None

    model_config = {"from_attributes": True}


class JobSettingUpdate(BaseModel):
    """PATCH-style: передавать только изменяемые поля. Непереданные — без изменений."""

    enabled: bool | None = None
    queue_name: str | None = None
    # Пустая строка → NULL (manual-only режим).
    cron_schedule: str | None = None
    rate_ms: int | None = Field(None, ge=0)
    max_retries: int | None = Field(None, ge=0, le=10)
    max_concurrency: int | None = Field(None, ge=1, le=20)
    extra_config: dict | None = None
