
    1i<                         d dl mZmZmZ d dlmZ d dlmZ  G d de      Z G d de      Z G d d	e      Z	 G d
 de      Z
y)    )	BaseModelFieldfield_validator)datetime)Optionalc                      e Zd ZU dZ edd      Zeed<    edd      Ze	ed<    ed	d
      Z
ee	   ed<    edd      Zee	   ed<    edd      Zee	   ed<    edd      Zeed<    edd      Zeed<    edddd      Zeed<    edd      Ze	ed<    ed      ed                Z ed      ed!               Z ed      ed"               Z ed      ed#               Zy)$SiteSettingsBasezBase schema for site settingsFz!Enable/disable automated scraping)defaultdescriptionscraping_enableddailyz)Frequency: 'daily', 'weekly', or 'custom'scraping_frequencyz02:00zKTime to run scraping (UTC). Format: HH:MM. Can be null for custom frequencyscraping_timemondayz0For weekly scraping: day of week (monday-sunday)scraping_day_of_weekNz5Custom cron expression (used when frequency='custom')scraping_custom_cronTzEnable SERP API discoveryenable_discoveryzRun browser in headless modeheadless_mode      <   zPage load timeout in seconds)r
   geler   timeout_secondsUTCzQClient timezone for scheduling (e.g., 'Europe/Madrid', 'America/New_York', 'UTC')client_timezonec                 r   ||S t        |t              s|S |j                  d      }t        |      dk7  rt	        d      	 t        |d         t        |d         }}d|cxk  rdk  r$n t	        d      d|cxk  rdk  st	        d       t	        d      	 |S # t        t        f$ r t	        d	      w xY w)
zValidate time format is HH:MM:   zTime format must be HH:MMr         ;   zInvalid time rangez#Time format must be HH:MM (24-hour))
isinstancestrsplitlen
ValueErrorint	TypeError)clsvpartshourminutes        ?/var/www/html/marco-python-backend/app/schemas/site_settings.pyvalidate_time_formatz%SiteSettingsBase.validate_time_format!   s     9H!S!Hu:?899	DuQx=#eAh-&DOO !566 )*V(9r(9 !566 ): !566 ):  I& 	DBCC	Ds   AB B6c                 $    |dvrt        d      |S )z+Validate frequency is one of allowed values)r   weeklycustomz0Frequency must be 'daily', 'weekly', or 'custom')r'   )r*   r+   s     r/   validate_frequencyz#SiteSettingsBase.validate_frequency4   s     11OPP    c                     ||S g d}|j                         |vrt        ddj                  |             |j                         S )z Validate day of week if provided)r   tuesday	wednesdaythursdayfridaysaturdaysundayzDay must be one of: z, )lowerr'   join)r*   r+   allowed_dayss      r/   validate_day_of_weekz%SiteSettingsBase.validate_day_of_week<   sJ     9He779L(3DIIl4K3LMNNwwyr5   c                     |yddl }	 |j                  |       |S # |j                  j                  $ r t	        d| d      w xY w)zValidate timezone is validNr   r   zInvalid timezone: zH. Use IANA timezone names like 'Europe/Madrid', 'America/New_York', etc.)pytztimezone
exceptionsUnknownTimeZoneErrorr'   )r*   r+   rB   s      r/   validate_timezonez"SiteSettingsBase.validate_timezoneG   sW     9	MM!H33 	1!4|}~~	s	    )A)__name__
__module____qualname____doc__r   r   bool__annotations__r   r$   r   r   r   r   r   r   r   r(   r   r   classmethodr0   r4   r@   rF    r5   r/   r	   r	      sf   '"5>abdb#?  $)a$M8C=  +0F+(3-  +0K+(3-  #4=XYdY:XYM4Y bFdeOSe gOS 
 _%  &" )*  + +,  - &'	  (	r5   r	   c                   $    e Zd ZdZ G d d      Zy)SiteSettingsUpdatez!Schema for updating site settingsc                       e Zd ZdZy)SiteSettingsUpdate.ConfigTNrG   rH   rI   from_attributesrN   r5   r/   ConfigrR   W       r5   rU   N)rG   rH   rI   rJ   rU   rN   r5   r/   rP   rP   U   s    + r5   rP   c                       e Zd ZU dZeed<   dZee   ed<   dZ	ee
   ed<   dZee
   ed<   eed<   eed<    G d	 d
      Zy)SiteSettingsResponsez!Schema for site settings responseidNlast_scheduled_runlast_scheduled_run_statuslast_scheduled_run_summary
created_at
updated_atc                       e Zd ZdZy)SiteSettingsResponse.ConfigTNrS   rN   r5   r/   rU   r`   d   rV   r5   rU   )rG   rH   rI   rJ   r(   rL   rZ   r   r   r[   r$   r\   rU   rN   r5   r/   rX   rX   [   sN    +G-1*1/3x}3044 r5   rX   c                   :    e Zd ZU dZeed<   eed<   eed<   eed<   y)ScheduledScrapingOutputz*Output for scheduled scraping job responsemessageproducts_scrapedtotal_violationsstatusN)rG   rH   rI   rJ   r$   rL   r(   rN   r5   r/   rb   rb   h   s    4LKr5   rb   N)pydanticr   r   r   r   typingr   r	   rP   rX   rb   rN   r5   r/   <module>ri      sH    6 6  Ly L^) 
+ 
i r5   