"""Driver command handlers — Phase 10.1."""
from __future__ import annotations

from uuid import UUID

from sqlalchemy.ext.asyncio import AsyncSession

from app.models.types import DriverLifecycleAction
from app.schemas.drivers import (
    DriverCreate,
    DriverCredentialCreate,
    DriverDocumentCreate,
    DriverLifecycleRequest,
    DriverUpdate,
)
from app.services.drivers import DriverService
from shared.security import CurrentUser


class DriverCommands:
    def __init__(self, session: AsyncSession) -> None:
        self.service = DriverService(session)

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

    async def update(
        self,
        tenant_id: UUID,
        driver_id: UUID,
        body: DriverUpdate,
        *,
        actor: CurrentUser | None,
    ):
        return await self.service.update(tenant_id, driver_id, body, actor=actor)

    async def activate(
        self,
        tenant_id: UUID,
        driver_id: UUID,
        body: DriverLifecycleRequest,
        *,
        actor: CurrentUser | None,
    ):
        return await self.service.apply_lifecycle(
            tenant_id, driver_id, DriverLifecycleAction.ACTIVATE, body, actor=actor
        )

    async def suspend(
        self,
        tenant_id: UUID,
        driver_id: UUID,
        body: DriverLifecycleRequest,
        *,
        actor: CurrentUser | None,
    ):
        return await self.service.apply_lifecycle(
            tenant_id, driver_id, DriverLifecycleAction.SUSPEND, body, actor=actor
        )

    async def resume(
        self,
        tenant_id: UUID,
        driver_id: UUID,
        body: DriverLifecycleRequest,
        *,
        actor: CurrentUser | None,
    ):
        return await self.service.apply_lifecycle(
            tenant_id, driver_id, DriverLifecycleAction.RESUME, body, actor=actor
        )

    async def deactivate(
        self,
        tenant_id: UUID,
        driver_id: UUID,
        body: DriverLifecycleRequest,
        *,
        actor: CurrentUser | None,
    ):
        return await self.service.apply_lifecycle(
            tenant_id, driver_id, DriverLifecycleAction.DEACTIVATE, body, actor=actor
        )

    async def block(
        self,
        tenant_id: UUID,
        driver_id: UUID,
        body: DriverLifecycleRequest,
        *,
        actor: CurrentUser | None,
    ):
        return await self.service.apply_lifecycle(
            tenant_id, driver_id, DriverLifecycleAction.BLOCK, body, actor=actor
        )

    async def unblock(
        self,
        tenant_id: UUID,
        driver_id: UUID,
        body: DriverLifecycleRequest,
        *,
        actor: CurrentUser | None,
    ):
        return await self.service.apply_lifecycle(
            tenant_id, driver_id, DriverLifecycleAction.UNBLOCK, body, actor=actor
        )

    async def archive(
        self,
        tenant_id: UUID,
        driver_id: UUID,
        body: DriverLifecycleRequest,
        *,
        actor: CurrentUser | None,
    ):
        return await self.service.apply_lifecycle(
            tenant_id, driver_id, DriverLifecycleAction.ARCHIVE, body, actor=actor
        )

    async def soft_delete(
        self, tenant_id: UUID, driver_id: UUID, *, actor: CurrentUser | None
    ):
        return await self.service.soft_delete(tenant_id, driver_id, actor=actor)

    async def add_credential(
        self,
        tenant_id: UUID,
        driver_id: UUID,
        body: DriverCredentialCreate,
        *,
        actor: CurrentUser | None,
    ):
        return await self.service.add_credential(
            tenant_id, driver_id, body, actor=actor
        )

    async def add_document(
        self,
        tenant_id: UUID,
        driver_id: UUID,
        body: DriverDocumentCreate,
        *,
        actor: CurrentUser | None,
    ):
        return await self.service.add_document(tenant_id, driver_id, body, actor=actor)
