from logging import getLogger

from fastapi import APIRouter
from orjson import loads

from shared.redis import client as cache

from . import schema as s

logger = getLogger(__name__)
router = APIRouter(
    prefix='/vitacore',
    tags=[
        'Витакор',
    ],
)


@router.post('/hospComplaint')
async def callback(complaint: s.HospComplaint):
    value = await cache.get(f'complaint:{complaint.patID}')
    value = loads(value.decode()) if value else ''

    return s.ComplaintData(
        patId=complaint.patID,
        complaints=(
            f'{value} | {complaint.eventId} | {complaint.datetime} | '
            f'{complaint.MO_id}'
        ),
    )
