# Auto-generated by DjangoCFG - see CLAUDE.md

from __future__ import annotations

from typing import Any

from pydantic import BaseModel, ConfigDict, Field

from ..enums import PatchedScheduleCreateRequestActionType, ScheduleEventEventType, ScheduleRunStatus


class Schedule(BaseModel):
    """
    Serializer for schedule list view.

    Response model (includes read-only fields).
    """

    model_config = ConfigDict(
        validate_assignment=True,
        extra="allow",
        frozen=False,
    )

    id: Any = ...
    service: str = Field(description='Service this schedule belongs to')
    service_name: Any = ...
    name: str = Field(description="Schedule name (e.g., 'Daily pars...", max_length=255)
    description: str | None = Field(None, description='Schedule description')
    enabled: bool | None = Field(None, description='Whether schedule is active')
    cron_expression: str | None = Field(
    None,
    description='Cron expression in Unix format (...',
    max_length=100,
)
    frequency_display: Any = ...
    action_type: PatchedScheduleCreateRequestActionType | None = Field(
    None,
    description='Action type to execute  * `run` ...',
)
    next_run_at: str | None = Field(None, description='Next scheduled execution time')
    last_run_at: Any | None = Field(None, description='Last execution time')
    run_count: int = Field(description='Total number of runs')
    is_due: bool = ...
    created_at: Any = ...
    updated_at: Any = ...



class PaginatedScheduleList(BaseModel):
    """
    
    Response model (includes read-only fields).
    """

    model_config = ConfigDict(
        validate_assignment=True,
        extra="allow",
        frozen=False,
    )

    count: int = Field(description='Total number of items across all...')
    page: int = Field(description='Current page number (1-based)')
    pages: int = Field(description='Total number of pages')
    page_size: int = Field(description='Number of items per page')
    has_next: bool = Field(description='Whether there is a next page')
    has_previous: bool = Field(description='Whether there is a previous page')
    next_page: int | None = Field(None, description='Next page number (null if no nex...')
    previous_page: int | None = Field(None, description='Previous page number (null if no...')
    results: list[Schedule] = Field(description='Array of items for current page')



class ScheduleCreateRequest(BaseModel):
    """
    Serializer for creating/updating schedules.

    Request model (no read-only fields).
    """

    model_config = ConfigDict(
        validate_assignment=True,
        extra="allow",
        frozen=False,
    )

    service: str = Field(description='Service this schedule belongs to')
    name: str = Field(
    description="Schedule name (e.g., 'Daily pars...",
    min_length=1,
    max_length=255,
)
    description: str | None = Field(None, description='Schedule description')
    enabled: bool | None = Field(None, description='Whether schedule is active')
    cron_expression: str | None = Field(
    None,
    description='Cron expression in Unix format (...',
    min_length=1,
    max_length=100,
)
    timezone: str | None = Field(
    None,
    description="Timezone for schedule (e.g., 'Eu...",
    min_length=1,
    max_length=50,
)
    action_type: PatchedScheduleCreateRequestActionType | None = Field(
    None,
    description='Action type to execute  * `run` ...',
)
    action_params: dict[str, Any] | None = Field(
    None,
    description='Parameters to pass to the action...',
)
    timeout_seconds: int | None = Field(
    None,
    description='Execution timeout (1 hour defaul...',
    ge=1,
    le=86400,
)
    max_retries: int | None = Field(
    None,
    description='Maximum retry attempts on failure',
    ge=0,
    le=10,
)
    retry_delay_seconds: int | None = Field(
    None,
    description='Delay between retry attempts',
    ge=1,
    le=3600,
)



class ScheduleCreate(BaseModel):
    """
    Serializer for creating/updating schedules.

    Response model (includes read-only fields).
    """

    model_config = ConfigDict(
        validate_assignment=True,
        extra="allow",
        frozen=False,
    )

    service: str = Field(description='Service this schedule belongs to')
    name: str = Field(description="Schedule name (e.g., 'Daily pars...", max_length=255)
    description: str | None = Field(None, description='Schedule description')
    enabled: bool | None = Field(None, description='Whether schedule is active')
    cron_expression: str | None = Field(
    None,
    description='Cron expression in Unix format (...',
    max_length=100,
)
    timezone: str | None = Field(
    None,
    description="Timezone for schedule (e.g., 'Eu...",
    max_length=50,
)
    action_type: PatchedScheduleCreateRequestActionType | None = Field(
    None,
    description='Action type to execute  * `run` ...',
)
    action_params: dict[str, Any] | None = Field(
    None,
    description='Parameters to pass to the action...',
)
    timeout_seconds: int | None = Field(
    None,
    description='Execution timeout (1 hour defaul...',
    ge=1,
    le=86400,
)
    max_retries: int | None = Field(
    None,
    description='Maximum retry attempts on failure',
    ge=0,
    le=10,
)
    retry_delay_seconds: int | None = Field(
    None,
    description='Delay between retry attempts',
    ge=1,
    le=3600,
)



class ScheduleDetail(BaseModel):
    """
    Serializer for schedule detail view with all fields.

    Response model (includes read-only fields).
    """

    model_config = ConfigDict(
        validate_assignment=True,
        extra="allow",
        frozen=False,
    )

    id: Any = ...
    service: str = Field(description='Service this schedule belongs to')
    service_name: Any = ...
    name: str = Field(description="Schedule name (e.g., 'Daily pars...", max_length=255)
    description: str | None = Field(None, description='Schedule description')
    enabled: bool | None = Field(None, description='Whether schedule is active')
    cron_expression: str | None = Field(
    None,
    description='Cron expression in Unix format (...',
    max_length=100,
)
    frequency_display: Any = ...
    timezone: str | None = Field(
    None,
    description="Timezone for schedule (e.g., 'Eu...",
    max_length=50,
)
    action_type: PatchedScheduleCreateRequestActionType | None = Field(
    None,
    description='Action type to execute  * `run` ...',
)
    action_params: dict[str, Any] | None = Field(
    None,
    description='Parameters to pass to the action...',
)
    timeout_seconds: int | None = Field(
    None,
    description='Execution timeout (1 hour defaul...',
    ge=1,
    le=86400,
)
    max_retries: int | None = Field(
    None,
    description='Maximum retry attempts on failure',
    ge=0,
    le=10,
)
    retry_delay_seconds: int | None = Field(
    None,
    description='Delay between retry attempts',
    ge=1,
    le=3600,
)
    next_run_at: str | None = Field(None, description='Next scheduled execution time')
    last_run_at: Any | None = Field(None, description='Last execution time')
    run_count: int = Field(description='Total number of runs')
    is_due: bool = ...
    version: int = Field(description='Version for optimistic locking')
    created_at: Any = ...
    updated_at: Any = ...



class PatchedScheduleCreateRequest(BaseModel):
    """
    Serializer for creating/updating schedules.

    Request model (no read-only fields).
    """

    model_config = ConfigDict(
        validate_assignment=True,
        extra="allow",
        frozen=False,
    )

    service: str | None = Field(None, description='Service this schedule belongs to')
    name: str | None = Field(
    None,
    description="Schedule name (e.g., 'Daily pars...",
    min_length=1,
    max_length=255,
)
    description: str | None = Field(None, description='Schedule description')
    enabled: bool | None = Field(None, description='Whether schedule is active')
    cron_expression: str | None = Field(
    None,
    description='Cron expression in Unix format (...',
    min_length=1,
    max_length=100,
)
    timezone: str | None = Field(
    None,
    description="Timezone for schedule (e.g., 'Eu...",
    min_length=1,
    max_length=50,
)
    action_type: PatchedScheduleCreateRequestActionType | None = Field(
    None,
    description='Action type to execute  * `run` ...',
)
    action_params: dict[str, Any] | None = Field(
    None,
    description='Parameters to pass to the action...',
)
    timeout_seconds: int | None = Field(
    None,
    description='Execution timeout (1 hour defaul...',
    ge=1,
    le=86400,
)
    max_retries: int | None = Field(
    None,
    description='Maximum retry attempts on failure',
    ge=0,
    le=10,
)
    retry_delay_seconds: int | None = Field(
    None,
    description='Delay between retry attempts',
    ge=1,
    le=3600,
)



class ScheduleEvent(BaseModel):
    """
    Serializer for schedule events.

    Response model (includes read-only fields).
    """

    model_config = ConfigDict(
        validate_assignment=True,
        extra="allow",
        frozen=False,
    )

    id: Any = ...
    schedule: Any = ...
    schedule_name: Any = ...
    run: Any | None = Field(None, description='Related run if applicable')
    event_type: ScheduleEventEventType = Field(description='* `created` - Schedule created *...')
    message: Any = Field(description='Event description')
    message_preview: Any = ...
    context: dict[str, Any] = Field(description='Additional context data')
    source: Any = Field(description='Where event originated: server, ...')
    timestamp: Any = ...



class PaginatedScheduleEventList(BaseModel):
    """
    
    Response model (includes read-only fields).
    """

    model_config = ConfigDict(
        validate_assignment=True,
        extra="allow",
        frozen=False,
    )

    count: int = Field(description='Total number of items across all...')
    page: int = Field(description='Current page number (1-based)')
    pages: int = Field(description='Total number of pages')
    page_size: int = Field(description='Number of items per page')
    has_next: bool = Field(description='Whether there is a next page')
    has_previous: bool = Field(description='Whether there is a previous page')
    next_page: int | None = Field(None, description='Next page number (null if no nex...')
    previous_page: int | None = Field(None, description='Previous page number (null if no...')
    results: list[ScheduleEvent] = Field(description='Array of items for current page')



class ScheduleRun(BaseModel):
    """
    Serializer for schedule run list.

    Response model (includes read-only fields).
    """

    model_config = ConfigDict(
        validate_assignment=True,
        extra="allow",
        frozen=False,
    )

    id: Any = ...
    schedule: Any = ...
    schedule_name: Any = ...
    status: ScheduleRunStatus = Field(description='* `pending` - Pending * `running...')
    scheduled_at: Any = Field(description='When it was supposed to run')
    started_at: Any | None = Field(None, description='When execution started')
    finished_at: Any | None = Field(None, description='When execution finished')
    duration_seconds: float = ...
    items_processed: int = Field(description='Items processed in this run')
    attempt: int = Field(description='Attempt number (1 = first try)')
    error_message: Any = Field(description='Error message if failed')
    created_at: Any = ...



class PaginatedScheduleRunList(BaseModel):
    """
    
    Response model (includes read-only fields).
    """

    model_config = ConfigDict(
        validate_assignment=True,
        extra="allow",
        frozen=False,
    )

    count: int = Field(description='Total number of items across all...')
    page: int = Field(description='Current page number (1-based)')
    pages: int = Field(description='Total number of pages')
    page_size: int = Field(description='Number of items per page')
    has_next: bool = Field(description='Whether there is a next page')
    has_previous: bool = Field(description='Whether there is a previous page')
    next_page: int | None = Field(None, description='Next page number (null if no nex...')
    previous_page: int | None = Field(None, description='Previous page number (null if no...')
    results: list[ScheduleRun] = Field(description='Array of items for current page')



class ScheduleToggleRequest(BaseModel):
    """
    Serializer for enabling/disabling schedule.

    Request model (no read-only fields).
    """

    model_config = ConfigDict(
        validate_assignment=True,
        extra="allow",
        frozen=False,
    )

    enabled: bool = ...



class ScheduleTriggerRequest(BaseModel):
    """
    Serializer for manually triggering a schedule.

    Request model (no read-only fields).
    """

    model_config = ConfigDict(
        validate_assignment=True,
        extra="allow",
        frozen=False,
    )

    force: bool | None = Field(None, description='Force trigger even if SDK is off...')
    params: dict[str, Any] | None = Field(None, description='Override action params for this run')



