o
    [g3                     @   s\  d dl mZ d dlmZmZmZ d dlmZ d dlm	Z	 d dl
mZmZmZ d dlmZ d dlmZ e Zejded	ee	jee	jfd
edefddZedee	jfdededefddZejded	ee	jee	jfdefddZejded	ee	jee	jfd
edefddZejdee d	ee	jee	jfdefddZdS )    )List)	APIRouterDependsHTTPException)Session)deps)StepRecordCreateStepRecordResponseStepRecordUpdate)step_record_service)UserService/)response_modelpayloaddbc                 C   s   t j||j| d}|S )z{
    POST /api/v1/steps
    Saves the step data for the logged-in user.
    If a record already exists, it updates it.
    )user_idZ	step_data)r   Zcreate_step_recordidr   r   current_userrecord r   "/app/app/api/v1/endpoints/steps.pycreate_step_record_endpoint   s   r   z/stepsr   stepsc                 C   s&   d}t || }t|| |d ddiS )z
    Example endpoint for saving user steps.
    When a user earns points through their steps, a certain percentage of the earned points
    is awarded to the referrers in the referral chain.
    g{Gz?)referred_user_idearned_pointsmessagez5Steps saved and referral bonuses awarded if eligible.)intr   )r   r   r   Zconversion_rater   r   r   r   
save_steps   s   r   z/currentc                 C   s$   t j| |jd}|stddd|S )z
    GET /api/v1/steps/current
    Retrieves the step record for the logged-in user for the current day.
    If no record exists, a 404 error is raised.
    r   i  zNo step record found for today.)status_codedetail)r   Zget_current_step_recordr   r   )r   r   r   r   r   r    get_current_step_record_endpoint/   s   
r"   z/accumulatec                 C   s   t j||j| jd}|S )z
    PATCH /api/v1/steps/accumulate
    Accumulates new steps into today's record for the logged-in user.
    If no record exists for today, a new record will be created.
    )r   steps_increment)r   Zupdate_step_record_accumulationr   r#   r   r   r   r   accumulate_step_recordA   s   r$   z/allc                 C   s   t j| |jd}|S )zV
    GET /api/v1/steps/all
    Retrieves all step records for the logged-in user.
    r   )r   Zget_all_step_recordsr   )r   r   recordsr   r   r   get_all_step_records_endpointS   s   	r&   N)typingr   fastapir   r   r   sqlalchemy.ormr   Zapp.apir   Zapp.schemas.step_recordr   r	   r
   app.servicesr   app.services.user_servicer   routerpostget_dbget_current_userr   r   r   getr"   patchr$   r&   r   r   r   r   <module>   sZ    