
    x
hz*                        d dl mZmZmZmZ d dlZd dlmZmZm	Z	 d dl
mZmZmZmZ d dlmZmZmZmZmZ dZerd dlZd dlZ ej0                   ed            Zej7                  dd	
      Zej;                  ddded       ej;                  ddded       ej;                  ddded       ej;                  ddded       ej;                  ddded        G d de      Zy)    )absolute_importdivisionprint_functionunicode_literalsN)is_struct_typeis_union_typeis_void_type)basefmt_serial_typeSwiftBaseBackendundocumented)check_route_name_conflict	fmt_classfmt_funcfmt_varfmt_typeFargparsezswift-client-backendzGenerates a Swift class with an object for each namespace, and in each namespace object, a method for each route. This class assumes that the swift_types backend was used with the same output directory.)progdescriptionz-mz--module-nameTzSThe name of the Swift module to generate. Please exclude the .swift file extension.)requiredtypehelpz-cz--class-namez~The name of the Swift class that contains an object for each namespace, and in each namespace object, a method for each route.z-tz--transport-client-namez;The name of the Swift class that manages network API calls.z-yz--client-argszFThe client-side route arguments to append to each route by style type.z-zz--style-to-requestz?The dict that maps a style type to a Swift request object name.c                   @    e Zd ZdZeZd Zd Zd Zd Z	d
dZ
d Zd	 Zy)SwiftBackendaE  
    Generates Swift client base that implements route interfaces.

    Examples:

    ```
    open class ExampleClientBase {
        /// Routes within the namespace1 namespace. See Namespace1 for details.
        open var namespace1: Namespace1!
        /// Routes within the namespace2 namespace. See Namespace2 for details.
        open var namespace2: Namespace2!

        public init(client: ExampleTransportClient) {
            self.namespace1 = Namespace1(client: client)
            self.namespace2 = Namespace2(client: client)
        }
    }
    ```

    Here, `ExampleTransportClient` would contain the implementation of a handwritten,
    project-specific networking client. Additionally, the `Namespace1` object would
    have as its methods all routes in the `Namespace1` namespace. A hypothetical 'copy'
    enpoding might be implemented like:

    ```
    open func copy(fromPath fromPath: String, toPath: String) ->
                     ExampleRequestType<Namespace1.CopySerializer, Namespace1.CopyErrorSerializer> {
        let route = Namespace1.copy
        let serverArgs = Namespace1.CopyArg(fromPath: fromPath, toPath: toPath)
        return client.request(route, serverArgs: serverArgs)
    }
    ```

    Here, ExampleRequestType is a project-specific request type, parameterized by response and
    error serializers.
    c                    |j                   j                         D ]^  }t        |j                        }|j                  s%| j                  dj                  |            5  | j                  |       d d d        ` | j                  dj                  | j                  j                              5  | j                  |       d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)Nz{}Routes.swiftz{}.swift)
namespacesvaluesr   nameroutesoutput_to_relative_pathformat_generate_routesargsmodule_name_generate_client)selfapi	namespacens_classs       `/var/www/html/lionshead-backend/venv/lib/python3.12/site-packages/stone/backends/swift_client.pygeneratezSwiftBackend.generate{   s    ..0I 0H112B2I2I(2ST)))4 UT 1 ))**;*;DII<Q<Q*RS!!#& TS UT TSs    C0CC	C c           
         | j                  t               | j                  d       | j                          | j                  dj	                  | j
                  j                              5  g }|j                  j                         D ]?  }|j                  s|j                  |j                  t        |j                        f       A |D ]G  \  }}| j                  dj	                  ||             | j                  dj	                  ||             I | j                          | j                  d| j                  ddj	                  | j
                  j                        fg            5  |D ]&  \  }}| j                  d	j	                  ||             ( 	 d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)
Nzimport Alamofirezopen class {}z=/// Routes within the {} namespace. See {}Routes for details.zopen var {}: {}Routes!zpublic initclient{})r#   z"self.{} = {}Routes(client: client))emit_rawr
   emitblockr!   r#   
class_namer   r   r   appendr   r   function_block
_func_argstransport_client_name)r&   r'   namespace_fieldsr(   vartyps         r*   r%   zSwiftBackend._generate_client   sq   d		$%		ZZ..tyy/C/CDE! ^^224	##$++Y^^,5inn,E-G H 5 -S		 66<fS#6FH		299#sCD - IIK$$]DII,K,K LMN:P$ Q 0HCIIBII#sST !1Q FEQ Q FEs+   +,F8CF8.,F,F8,F5	1F88Gc                    t        |       t        |j                        }| j                  t               | j                  dj                  |j                               | j                  dj                  |            5  | j                  dj                  | j                  j                               ddj                  | j                  j                        fg}| j                  d| j                  |            5  | j                  d       d d d        | j                          |j                  D ]  }| j                  ||        	 d d d        y # 1 sw Y   FxY w# 1 sw Y   y xY w)Nz/// Routes for the {} namespacezopen class {}Routeszpublic let client: {}r-   r.   initzself.client = client)r   r   r   r/   r
   r0   r!   r1   r#   r6   r4   r5   r   _generate_route)r&   r(   r)   r#   routes        r*   r"   zSwiftBackend._generate_routes   s   !),Y^^,d		3::9>>JKZZ-44X>?II-44TYY5T5TUVt{{499+J+JKLMD$$VT__T-BC		01 D IIK"))$$Y6 * @? DC	 @?s%    A>E!>E;E!E	E!!E*c                     |j                   }t        |      }t        |      r| j                  ||      }|j                  D cg c][  }|j
                  rMt        |j                        |j
                  r&| j                  |j
                  | j                        nt        f] }}||fS t        |      rt        |j                        dj                  t        |j                        t        |j                              fg}t        |j                        |j
                  r&| j                  |j
                  | j                        n#dj                  t        |j                              fg}||fS t        |      rg nd|fg}g }||fS c c}w )N)r(   {}.{}zThe {} unionrequest)arg_data_typer   r   _struct_init_argsfieldsdocr   r   process_doc_docfr   r   r!   r   r	   )r&   r(   r=   	data_typearg_typearg_listfdoc_lists           r*   _get_route_argszSwiftBackend._get_route_args   sv   ''	I&)$--i9-MH 6?5E5EP5E !55 +/*:*:155$***M*,5E  P !! 9% 0'..)..)9Y^^+D3F G HH 0==   

;&4&;&;Iinn<U&VX YH !! *)4rIx;P:QHH!!Ps   A FNc           	         | j                  ||      \  }}|xs g }|xs g }t        |j                        }t        |j                  |j
                        }	|j                  r'| j                  |j                  | j                        }
ndj                  |	      }
| j                  |
dd       | j                  d       ||z   D ]3  \  }}dj                  |||nt              }| j                  |dd       5 | j                  d       d}|j                  t        |j                        t        |j                              }| j                  |dd       dd	j                  t        |j                        |	      fg}g }d
g}|D ]?  \  }}}|j!                  ||f       |j!                  ||f       |j!                  ||f       A t#        |j                        }t#        |j                        }| j%                  |       | j'                  dj                  |	      | j)                  |d      dj                  |||            5  | j                  dj                  t        |j                        |	             t+        |j                        r| j-                  |j                        D cg c]	  \  }}||f }}}|ddj                  || j)                  |            fgz  }| j                  dj                  || j)                  |                   nRt/        |j                        r=| j                  dj                  t1        |j                  j                                     t3        |j                        s|dgz  }||z  }dj                  | j)                  |d            }| j                  |       d d d        | j                          y c c}}w # 1 sw Y    xY w)NzThe {} routez/// x   )prefixwidthz///z- parameter {}: {}zx - returns: Through the response callback, the caller will receive a `{}` object on success or a `{}` object on failure.r=   r?   )r=   r=   z@discardableResult open func {}F)force_firstz
{}<{}, {}>)r#   return_typezlet route = {}.{}
serverArgsz{}({})zlet serverArgs = {}({})zlet serverArgs = {})rS   rS   zreturn client.request({})T)not_init)rL   r   rA   r   r   versionrD   rE   rF   r!   emit_wrapped_textr0   r   result_data_typeerror_data_typer   r3   r   #_maybe_generate_deprecation_warningr4   r5   r   rB   r   r   r	   )r&   r(   r=   req_obj_name
extra_args
extra_docsrI   rK   rH   	func_name	route_docr   rD   	param_docoutput	func_argsclient_argsreturn_argsvaluer9   rtypeetype_r#   txts                            r*   _emit_routezSwiftBackend._emit_route   s   !11)UC(%2
%2
E//0UZZ7	99((DJJ?I&--i8IysC		%!J.ID#,33D#VbcI""9V3"G / 			%Lx(>(>?'(=(=>@vfC@ gnnYy~~%>	JK
	 )* *D%OOT3K(dE]+e}- !+
   6 67 5 56007  !B!I!I)!T__X5_A(//eUK ! M II)009>>1JIVWe112484J4J5K^K^4_`4_qt4_`|X__XtW[G\-]^__			3::8T__UYEZ[\u223		/66wu?R?R?W?W7XYZ 3 34 <==;&K-44d;C IIcN)M* 			! aM Ms    A(O 3OD O O  O)c                    |j                   rdj                  t        |j                  |j                              }|j                   j
                  rZ|dj                  t        |j                   j
                  j                  |j                   j
                  j                              z  }| j                  dj                  |             y y )Nz{} is deprecated.z Use {}.z(@available(*, unavailable, message:"{}"))
deprecatedr!   r   r   rU   byr0   )r&   r=   msgs      r*   rY   z0SwiftBackend._maybe_generate_deprecation_warning  s    %,,Xejj%---PQC""z((U--0055u7G7G7J7J7R7RSU UII@GGLM     c           	         |j                   j                  d      }t        j                  | j                  j
                        }t        j                  | j                  j                        }||j                         vr| j                  ||||          y ||   D ]\  }t        |      \  }}||   }	|D 
cg c]  }
t        |
d d        }}
|D 
cg c]  }
|
d   |
d   f }}
| j                  |||	||       ^ y c c}
w c c}
w )Nstyler   )
attrsgetjsonloadsr#   rb   style_to_requestkeysri   tuple)r&   r(   r=   
route_typerb   rv   	args_datareq_obj_keytype_data_listrZ   	type_datar[   r\   s                r*   r<   zSwiftBackend._generate_route	  s    [[__W-
jj!6!67::dii&@&@A[--//Y/?
/KL(4	.3I.>+^/<EST^	eIcrN3^
TM[\^	y|Yr];^
\  E<ZX 5 U\s   6C<D)NN)__name__
__module____qualname____doc___cmdline_parsercmdline_parserr+   r%   r"   rL   ri   rY   r<    rn   r*   r   r   S   s6    #J %N'U,7&"&>@NYrn   r   )
__future__r   r   r   r   rt   stone.irr   r   r	   stone.backends.swiftr
   r   r   r   stone.backends.swift_helpersr   r   r   r   r   _MYPYtyping	importlibimport_modulestrr   ArgumentParserr   add_argumentr   r   rn   r*   <module>r      s>   R R  
   	 "9""3z?3 ))		G *    	     	C     		F     		Q     		J  EY# EYrn   