
    i.                       U d Z ddlmZ ddlZddlZddlZddlZddlmZ ddl	Z	ddl
mZ  ej                  e      Zi Zded<   dOdZdPd	ZdQd
Z eddddddgg ddddd
       eddddddgddgdddd
       eddd d!d"gg d#ddd$d
       ed%d&d'dd(d)gg d*dddd
       ed+d,d-d.d/gg d0dddd
      gZd1ed2<    ed3d4d5dd6gd7d8gddd9d
       ed:d;d<dd=gd7d>gddd9d
       ed?d@dAddBgg dCddd$d
       edDdEdFddGgd7d8gddd9d
       edHdIdJddKgd7d>gddd9d
      gZd1edL<   eez   D ]
  Z ee        h dMZdRdSdNZy)Tu  
Platform Registry — MODULE 7
==============================
In-memory registry of PlatformConfig entries for the KB ingestion pipeline.

Stories implemented:
  7.01  Registry CRUD operations (register, get, list) with case-insensitive lookup
  7.02  Pre-built Core 5 configs (HubSpot, GHL, Telnyx, Xero, Stripe)
  7.03  Pre-built AU Trades 5 configs (ServiceM8, Fergus, simPRO, AroFlo, Tradify)
  7.04  load_custom_platforms() — import YAML configs from a directory
    )annotationsN)Optional)PlatformConfigzdict[str, PlatformConfig]PLATFORM_REGISTRYc                F    | t         | j                  j                         <   y)zMRegister a PlatformConfig.  Overwrites any existing entry with the same name.N)r   namelower)configs    2/mnt/e/genesis-system/core/kb/platform_registry.pyregister_platformr   $   s    -3fkk'')*    c                x    t         j                  | j                               }|yt        j                  |      S )z
    Return a deep-copy of the named PlatformConfig, or None if not found.

    Deep-copy prevents callers from mutating the registry entry.
    Lookup is case-insensitive.
    N)r   getr	   copydeepcopy)r   entrys     r   get_platformr   )   s1     !!$**,/E}==r   c                 <    t        t        j                               S )zCReturn a sorted list of all registered platform names (lower-case).)sortedr   keys r   r   list_platformsr   6   s    #((*++r   hubspotHubSpotzhttps://knowledge.hubspot.comz)https://knowledge.hubspot.com/sitemap.xmlzhttps://knowledge.hubspot.com/*z https://developers.hubspot.com/*)*/blog/**/marketing/*z*/resources/*z*/academy/*          )
r   display_namedocs_base_urlsitemap_urlurl_patternsexclude_patterns
chunk_sizechunk_overlap	max_pagesrefresh_hoursgohighlevelGoHighLevelzhttps://support.gohighlevel.comz!https://support.gohighlevel.com/*zhttps://help.gohighlevel.com/**/community/*z*/discussions/*telnyxTelnyxzhttps://developers.telnyx.comz)https://developers.telnyx.com/sitemap.xmlzhttps://developers.telnyx.com/*)z*/changelog/*z
*/status/*r   i  xeroXerozhttps://central.xero.comzhttps://central.xero.com/*zhttps://developer.xero.com/*)r,   r   */news/*stripeStripezhttps://docs.stripe.comz#https://docs.stripe.com/sitemap.xmlzhttps://docs.stripe.com/*)r   z*/newsroom/*z*/jobs/*zlist[PlatformConfig]_CORE_PLATFORMS	servicem8	ServiceM8zhttps://support.servicem8.comzhttps://support.servicem8.com/*r   r1   i  fergusFerguszhttps://support.fergus.comzhttps://support.fergus.com/*r   simprosimPROz!https://helpguide.simprogroup.comz#https://helpguide.simprogroup.com/*)r   r1   z*/careers/*arofloAroFlozhttps://support.aroflo.comzhttps://support.aroflo.com/*tradifyTradifyzhttps://support.tradifyhq.comzhttps://support.tradifyhq.com/*_AU_TRADES_PLATFORMS>   r   r!   r"   c                R   d}t         j                  j                  | d      }t        t	        j                  |            }|st
        j                  d|        y|D ]  }	 t        |dd      5 }t        j                  |      }ddd       t        t              st
        j                  d|       Xt        t        |j                               z
  }|rt
        j                  d	||       t!        t#        |d
         j%                         t#        |d         t#        |d         |j'                  d      |j'                  ddg      |j'                  dg       |j'                  dd      |j'                  di       t)        |j'                  dd            t)        |j'                  dd            t)        |j'                  dd            t)        |j'                  dd            t+        |j'                  dd                  }t-        |       |dz  }t
        j/                  d |j0                  |        |S # 1 sw Y   xY w# t        j2                  $ r"}	t
        j                  d!||	       Y d}	~	d}	~	wt4        $ r"}	t
        j                  d"||	       Y d}	~	Ed}	~	ww xY w)#a>  
    Load custom platform configs from YAML files in *config_dir*.

    Each YAML file may define one platform.  Required fields:
        name, display_name, docs_base_url

    Invalid or malformed files are skipped with a warning log.

    Returns:
        Number of platforms successfully loaded and registered.
    r   z*.y*mlz0load_custom_platforms: no YAML files found in %srzutf-8)encodingNu<   load_custom_platforms: %s is not a YAML mapping — skippinguC   load_custom_platforms: %s missing required field(s) %s — skippingr   r!   r"   r#   r$   *r%   	auth_typenoneauth_configr&   r   r'   r   r(   r   r)   r    use_browserlessF)r   r!   r"   r#   r$   r%   rD   rF   r&   r'   r(   r)   rG      z.load_custom_platforms: registered '%s' from %suA   load_custom_platforms: YAML parse error in %s — %s — skippinguA   load_custom_platforms: unexpected error in %s — %s — skipping)ospathjoinr   globloggerdebugopenyaml	safe_load
isinstancedictwarning_REQUIRED_YAML_FIELDSsetr   r   strr	   r   intboolr   infor   	YAMLError	Exception)

config_dirloadedpattern
yaml_filesrJ   fhdatamissingr
   excs
             r   load_custom_platformsre     sG    Fggll:x0G		'*+JGT .-	dC'2 *b~~b)* dD)RTX +c$))+.>>GY
 #f&,,. n!56!$"78 HH]3!XXnse<!%*<b!A((;7 HH]B7txxd;<!$((?C"@Adhh{D9:!$((?C"@A $TXX.?%G HF f%aKFKKH&++W[\K.` M]* *J ~~ 	NNSUY[^   	NNSUY[^ 	sI   !I/H;.I49I.EI;I	 IJ&I88J&J!!J&)r
   r   returnNone)r   rW   rf   zOptional[PlatformConfig])rf   z	list[str])zconfig/kb_platforms/)r]   rW   rf   rX   )__doc__
__future__r   r   rL   loggingrI   typingr   rP   core.kb.contractsr   	getLogger__name__rM   r   __annotations__r   r   r   r4   r?   	_platformrU   re   r   r   r   <module>rq      s  
 #    	   ,			8	$ 02 , 14

 , 5?-.

 %* "7/,

 
 !& 5?-


 !& 0(*


 #( /9'


 !cc)% cV  5-
 
 $ 2*
 
 $ 91


 !& 2*
 
 $ 5-
 
 W\. * \~ !#77 !Ii ! B Dr   