from datetime import datetime, date
from decimal import Decimal
from typing import Optional, List

from fastapi import APIRouter, Depends
from sqlmodel import Field, SQLModel

from ...db import get_session

from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession

router = APIRouter()


class HistoryTravelReimburse(SQLModel, table=True):
    id: Optional[int] = Field(default=None, primary_key=True)
    history_id: int
    history_procedure_id: int
    group: str
    guardian_id: Optional[int] = None
    procedure_id: int
    amount: float
    detail: str
    pdf_path: str
    signature_path: str
    document_path: str
    created_at: datetime
    updated_at: datetime
    created_by: int
    updated_by: Optional[int] = None


@router.post("/history_travel_reimburse", response_model=HistoryTravelReimburse)
async def create_history_travel_reimburse(history_travel_reimburse: HistoryTravelReimburse, session: AsyncSession = Depends(get_session)):
    session.add(history_travel_reimburse)
    await session.commit()
    await session.refresh(history_travel_reimburse)
    return history_travel_reimburse


@router.get("/history_travel_reimburse/{id}", response_model=HistoryTravelReimburse)
async def get_history_travel_reimburse(id: int, session: AsyncSession = Depends(get_session)):
    history_travel_reimburses = await session.execute(select(HistoryTravelReimburse).where(HistoryTravelReimburse.id == id))
    history_travel_reimburse = history_travel_reimburses.scalars().first()
    return history_travel_reimburse


@router.put("/history_travel_reimburse/{id}", response_model=HistoryTravelReimburse)
async def update_history_travel_reimburse(id: int, session: AsyncSession = Depends(get_session)):
    return None


@router.delete("/history_travel_reimburse/{id}")
async def delete_history_travel_reimburse(session: AsyncSession = Depends(get_session)):
    return None


@router.get("/history_travel_reimburse/patient/{patient_id}", response_model=HistoryTravelReimburse)
async def get_history_travel_reimburse_patient(patient_id: int, session: AsyncSession = Depends(get_session)):
    history_id = await session.execute(select(HistoryTravelReimburse.id).where(HistoryTravelReimburse.patient_id == patient_id))
    history_travel_reimburses = await session.execute(select(HistoryTravelReimburse).where(HistoryTravelReimburse.history_id == history_id))
    history_travel_reimburse = history_travel_reimburses.scalars().first()
    return history_travel_reimburse


@router.get("/history_travel_reimburse", response_model=HistoryTravelReimburse)
async def get_history_travel_reimburse_daily(session: AsyncSession = Depends(get_session)):
    return None


@router.get("/history_travel_reimburse/{id}", response_model=HistoryTravelReimburse)
async def get_history_travel_reimburse_pdf(id: int, session: AsyncSession = Depends(get_session)):
    history_travel_reimburses = await session.execute(select(HistoryTravelReimburse.pdf_path).where(HistoryTravelReimburse.id == id))
    history_travel_reimburse = history_travel_reimburses.scalars().first()
    return history_travel_reimburse


@router.post("/history_travel_reimburse/{id}/document", response_model=HistoryTravelReimburse)
async def upload_document(session: AsyncSession = Depends(get_session)):
    return None


@router.post("/history_travel_reimburse/{id}/signature")
async def upload_signature(session: AsyncSession = Depends(get_session)):
    return None
fastapi.APIRouter sqlalchemy.select fastapi.Depends sqlmodel.Field
[((295, 306), 'fastapi.APIRouter', 'APIRouter', ([], {}), '()\n', (304, 306), False, 'from fastapi import APIRouter, Depends\n'), ((385, 422), 'sqlmodel.Field', 'Field', ([], {'default': 'None', 'primary_key': '(True)'}), '(default=None, primary_key=True)\n', (390, 422), False, 'from sqlmodel import Field, SQLModel\n'), ((953, 973), 'fastapi.Depends', 'Depends', (['get_session'], {}), '(get_session)\n', (960, 973), False, 'from fastapi import APIRouter, Depends\n'), ((1292, 1312), 'fastapi.Depends', 'Depends', (['get_session'], {}), '(get_session)\n', (1299, 1312), False, 'from fastapi import APIRouter, Depends\n'), ((1713, 1733), 'fastapi.Depends', 'Depends', (['get_session'], {}), '(get_session)\n', (1720, 1733), False, 'from fastapi import APIRouter, Depends\n'), ((1869, 1889), 'fastapi.Depends', 'Depends', (['get_session'], {}), '(get_session)\n', (1876, 1889), False, 'from fastapi import APIRouter, Depends\n'), ((2099, 2119), 'fastapi.Depends', 'Depends', (['get_session'], {}), '(get_session)\n', (2106, 2119), False, 'from fastapi import APIRouter, Depends\n'), ((2654, 2674), 'fastapi.Depends', 'Depends', (['get_session'], {}), '(get_session)\n', (2661, 2674), False, 'from fastapi import APIRouter, Depends\n'), ((2856, 2876), 'fastapi.Depends', 'Depends', (['get_session'], {}), '(get_session)\n', (2863, 2876), False, 'from fastapi import APIRouter, Depends\n'), ((3271, 3291), 'fastapi.Depends', 'Depends', (['get_session'], {}), '(get_session)\n', (3278, 3291), False, 'from fastapi import APIRouter, Depends\n'), ((3420, 3440), 'fastapi.Depends', 'Depends', (['get_session'], {}), '(get_session)\n', (3427, 3440), False, 'from fastapi import APIRouter, Depends\n'), ((1369, 1399), 'sqlalchemy.select', 'select', (['HistoryTravelReimburse'], {}), '(HistoryTravelReimburse)\n', (1375, 1399), False, 'from sqlalchemy import select\n'), ((2161, 2194), 'sqlalchemy.select', 'select', (['HistoryTravelReimburse.id'], {}), '(HistoryTravelReimburse.id)\n', (2167, 2194), False, 'from sqlalchemy import select\n'), ((2305, 2335), 'sqlalchemy.select', 'select', (['HistoryTravelReimburse'], {}), '(HistoryTravelReimburse)\n', (2311, 2335), False, 'from sqlalchemy import select\n'), ((2933, 2972), 'sqlalchemy.select', 'select', (['HistoryTravelReimburse.pdf_path'], {}), '(HistoryTravelReimburse.pdf_path)\n', (2939, 2972), False, 'from sqlalchemy import select\n')]