"""Fleet command handlers — Phase 10.2."""
from __future__ import annotations

from uuid import UUID

from sqlalchemy.ext.asyncio import AsyncSession

from app.schemas.fleet import (
    FleetCreate,
    FleetUpdate,
    VehicleAssignmentCreate,
    VehicleAssignmentUpdate,
    VehicleCreate,
    VehicleTypeCreate,
    VehicleTypeUpdate,
    VehicleUpdate,
)
from app.services.fleet import FleetService, VehicleService, VehicleTypeService
from shared.security import CurrentUser


class FleetCommands:
    def __init__(self, session: AsyncSession) -> None:
        self.fleets = FleetService(session)
        self.types = VehicleTypeService(session)
        self.vehicles = VehicleService(session)

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

    async def update_fleet(
        self, tenant_id: UUID, fleet_id: UUID, body: FleetUpdate, *, actor: CurrentUser | None
    ):
        return await self.fleets.update(tenant_id, fleet_id, body, actor=actor)

    async def delete_fleet(self, tenant_id: UUID, fleet_id: UUID, *, actor: CurrentUser | None):
        return await self.fleets.soft_delete(tenant_id, fleet_id, actor=actor)

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

    async def update_vehicle_type(
        self, tenant_id: UUID, type_id: UUID, body: VehicleTypeUpdate, *, actor: CurrentUser | None
    ):
        return await self.types.update(tenant_id, type_id, body, actor=actor)

    async def delete_vehicle_type(
        self, tenant_id: UUID, type_id: UUID, *, actor: CurrentUser | None
    ):
        return await self.types.soft_delete(tenant_id, type_id, actor=actor)

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

    async def update_vehicle(
        self, tenant_id: UUID, vehicle_id: UUID, body: VehicleUpdate, *, actor: CurrentUser | None
    ):
        return await self.vehicles.update(tenant_id, vehicle_id, body, actor=actor)

    async def delete_vehicle(
        self, tenant_id: UUID, vehicle_id: UUID, *, actor: CurrentUser | None
    ):
        return await self.vehicles.soft_delete(tenant_id, vehicle_id, actor=actor)

    async def create_assignment(
        self,
        tenant_id: UUID,
        vehicle_id: UUID,
        body: VehicleAssignmentCreate,
        *,
        actor: CurrentUser | None,
    ):
        return await self.vehicles.create_assignment(
            tenant_id, vehicle_id, body, actor=actor
        )

    async def update_assignment(
        self,
        tenant_id: UUID,
        vehicle_id: UUID,
        assignment_id: UUID,
        body: VehicleAssignmentUpdate,
        *,
        actor: CurrentUser | None,
    ):
        return await self.vehicles.update_assignment(
            tenant_id, vehicle_id, assignment_id, body, actor=actor
        )
