
    ic                         d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	m
Z
 d dlmZ d dlmZ dd	lmZmZmZmZmZmZ dd
lmZ ddlmZ  e
dgde e	dddddddidd      g       G d de             Zy)    )IsAuthenticated)Response)APIView)get_object_or_404)OpenApiExampleextend_schema)Booking)	Structure   )build_configured_exemption_mapbuild_monthly_rate_mapbuild_period_boundscalculate_city_tax_report$get_missing_city_tax_settings_fieldsnormalize_platform_tokens)StructureCityTaxSettings)CityTaxPreviewRequestSerializerzCity Taxz7Preview city tax calculation for a structure and periodzPreview Request   i  )
from_monthto_monthyear1)periodratesT)namevaluerequest_only)tagssummaryrequestexamplesc                       e Zd ZegZd Zy)CityTaxPreviewAPIViewc                    t        t        |      }t        |j                        }|j	                  d       |j
                  d   }|j
                  d   }|j
                  j                  d      }|j
                  j                  d      }t        t        |d	      }	t        |	      }
|
rt        d
|
dd      S |d   }t        ||      }t        |	j                        }t        |	j                        }t        |      \  }}}t         j"                  j%                  |||      j'                  d      j)                  d      }|r|j%                  |      }|r|j%                  |      }t+        |j-                  dd      |||	j.                  |t1        |	j2                  xs d      t1        |	j4                  xs d      ||t7        |	j                  xs g       
      }t        |j8                        S )N)id)dataT)raise_exceptionr   r   property_type_idproperty_id)	structure	is_activez!City tax configuration incomplete)errormissing_fieldsi  )statusr   )r*   check_in_date__ltcheck_out_date__gtpropertyguests)r(   )r)   check_in_dater%   r   )
bookingsr   rates_overridedefault_ratemonthly_rate_mapmax_taxable_nightsminor_age_limitconfigured_exemptionsplatform_exemptionsplatform_exemption_labels)r   r
   r   r&   is_validvalidated_datagetr   r   r   r   r   exemption_reasonsr   r;   r   r	   objectsfilterselect_relatedprefetch_relatedr   order_byr6   intr8   r9   listpreview_payload)selfr    structure_idr*   
serializerr   r5   r(   r)   settingsmissingperiod_start_yearr7   r:   r;   period_startperiod_end_exclusive_r4   results                       -/backend/structures/views_city_tax_preview.pypostzCityTaxPreviewAPIView.post*   s   %iLA	4',,G
D1**84#227;%44889KL //33MB$$
 7x@@&-   #6N1)=NO >&&!
 88T8TU0CF0K-*A OO""#"6#/ # 
 ^J'h' 	 8HIH;?H*&&=)!..-"8#>#>#C!D 8 8 =A>"7 3&*8+G+G+M2&N
 ..//    N)__name__
__module____qualname__r   permission_classesrT    rU   rS   r#   r#      s      **@0rU   r#   N)rest_framework.permissionsr   rest_framework.responser   rest_framework.viewsr   django.shortcutsr   drf_spectacular.utilsr   r   bookings.modelsr	   structures.modelsr
   city_tax_servicer   r   r   r   r   r   modelsr   serializers_city_tax_previewr   r#   rZ   rU   rS   <module>re      s    6 , ( . ? # '  - I 
E+")*4Hq 	
		C0G C0C0rU   