"""Doctor panel command handlers — Phase 13.2."""
from __future__ import annotations

from uuid import UUID

from sqlalchemy.ext.asyncio import AsyncSession

from app.schemas.doctor_panel import (
    VisitNoteCreate,
    VisitNoteUpdate,
    VisitSessionActionRequest,
    VisitSessionCreate,
)
from app.services.doctor_panel import VisitNoteService, VisitSessionService
from shared.security import CurrentUser


class DoctorPanelCommands:
    def __init__(self, session: AsyncSession) -> None:
        self.sessions = VisitSessionService(session)
        self.notes = VisitNoteService(session)

    async def create_session(
        self, tenant_id: UUID, body: VisitSessionCreate, *, actor: CurrentUser | None = None
    ):
        return await self.sessions.create(tenant_id, body, actor=actor)

    async def start_session(
        self,
        tenant_id: UUID,
        visit_session_id: UUID,
        body: VisitSessionActionRequest,
        *,
        actor: CurrentUser | None = None,
    ):
        return await self.sessions.start(tenant_id, visit_session_id, body, actor=actor)

    async def finish_session(
        self,
        tenant_id: UUID,
        visit_session_id: UUID,
        body: VisitSessionActionRequest,
        *,
        actor: CurrentUser | None = None,
    ):
        return await self.sessions.finish(tenant_id, visit_session_id, body, actor=actor)

    async def defer_session(
        self,
        tenant_id: UUID,
        visit_session_id: UUID,
        body: VisitSessionActionRequest,
        *,
        actor: CurrentUser | None = None,
    ):
        return await self.sessions.defer(tenant_id, visit_session_id, body, actor=actor)

    async def call_next(
        self,
        tenant_id: UUID,
        visit_session_id: UUID,
        body: VisitSessionActionRequest,
        *,
        actor: CurrentUser | None = None,
    ):
        return await self.sessions.call_next(tenant_id, visit_session_id, body, actor=actor)

    async def create_note(
        self, tenant_id: UUID, body: VisitNoteCreate, *, actor: CurrentUser | None = None
    ):
        return await self.notes.create(tenant_id, body, actor=actor)

    async def update_note(
        self,
        tenant_id: UUID,
        note_id: UUID,
        body: VisitNoteUpdate,
        *,
        actor: CurrentUser | None = None,
    ):
        return await self.notes.update(tenant_id, note_id, body, actor=actor)
