# ws_package/entities/org_entity.py

from typing import Optional, Dict, Any
from pydantic import BaseModel, field_validator


def normalize_timezone_preference(value: Any) -> int:
    """0 = timezone/time checks ON, 1 = checks OFF (default)."""
    if value in (0, "0", False):
        return 0
    return 1


class OrgEntity(BaseModel):
    org_id: int
    user_id: int
    screenshot_interval: int
    date: Optional[str] = None
    appandurlstatus: int
    ssfrequencystatus: int
    screenshotblurstatus: int
    livescreenshotstatus: int
    idlenotes_status: int
    break_limit: str
    break_status: int
    notes_char_limit: str
    idle_limit: str
    idle_time_limit_in_seconds: Optional[int] = None  # From API, defaults to 3600 if not provided
    can_delete_scrnshots: int
    restrict_timer_to_jobsite: int
    todos_files_upload_limit: int
    org_timezone: str
    user_timezone: str
    user_timezone_gmt: str
    user_timezone_gmt_dst: str
    user_timezone_gmt_shortcode: str
    bulkInvite: bool
    timeInterval: str
    blur_intensity: Optional[int] = None
    img_quality: Optional[int] = None
    notification_status: Optional[int] = None
    # Weekly limit data
    weekly_limit: Optional[Dict[str, Any]] = None
    org_week_start_day: Optional[str] = None
    worked_total_hours_week: Optional[str] = None
    worked_total_hours_week_leaving_today: Optional[str] = None
    daily_limit: Optional[str] = None
    weekly_limit_hours: Optional[str] = None
    worked_total_hours_today: Optional[str] = None
    limit_action: Optional[str] = None  # "just_notify" or "stop_timer"
    # 0 = checks ON, 1 = checks OFF (organization settings API)
    timezone_preference: int = 1

    @field_validator("timezone_preference", mode="before")
    @classmethod
    def _coerce_timezone_preference(cls, value):
        return normalize_timezone_preference(value)

