o
    0h                     @   sR   d dl mZ ddlmZ G dd dejZG dd dejZG dd	 d	ejZd
S )    )serializers   )Configurationc                   @   s   e Zd ZG dd dZdS )ConfigurationSerializerc                   @   s   e Zd ZeZg dZdS )zConfigurationSerializer.Metaheadericoncolor	questionsN)__name__
__module____qualname__r   modelfields r   r   ?C:\Users\Denis\Desktop\TimeStamps\configurations\serializers.pyMeta   s    r   N)r   r   r   r   r   r   r   r   r      s    r   c                   @   sD   e Zd ZejddZejddZejddZeje de	dZ
dS )FunctionConfigSerializer   )
max_lengthd   2   F)childrequireddefaultN)r   r   r   r   	CharFieldr   r   r	   	ListFieldlistr
   r   r   r   r   r   	   s
    r   c                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
MenuSerializerc              	   C   s  t |ts
tdi }| D ]q\}}|dv rXt |ts%t| d| D ]+\}}t |ts;td| d|dd|dd|d	d|d
g ||d}  |S t |tsftd| d|dd|dd|d	d|d
g |d d} |S |S )NzData must be a dictionaryInMenuOutMenuz value must be a dictionaryzConfiguration for z must be a dictionaryr    r   r	   r
   )r   r   r	   r
   function_ref_id	menu_type)
isinstancedictr   ValidationErroritemsget)selfdataresultkeyvalueZfunction_idconfigr   r   r   to_internal_value   s>   












z MenuSerializer.to_internal_valuec                 C   s   t jjdi |S )Nr   )r   objectscreate)r*   validated_datar   r   r   r2   7   s   zMenuSerializer.createc                 C   s  t |tr+|jr|j|j|j|j|j|jpg diiS |j|j|j|j|jp'g diS i }i i d}|D ]H}t |ts<q4|jdkrT|j|j|j|jpKg d|d |j< q4|jdkrl|j|j|j|jpcg d|d |j< q4|j|j|j|jpvg d||j< q4| D ]
\}}|r|||< q|S )Nr   r   r    r!   )	r%   r   r$   r#   r   r   r	   r
   r(   )r*   instancer,   Zmenu_configsr/   r$   	functionsr   r   r   to_representation:   s^   




	z MenuSerializer.to_representationc                 C   s   |S )Nr   )r*   r+   r   r   r   validate|   s   zMenuSerializer.validateN)r   r   r   r0   r2   r6   r7   r   r   r   r   r      s
    'Br   N)	rest_frameworkr   modelsr   ModelSerializerr   
Serializerr   r   r   r   r   r   <module>   s
    