"""Pricing command handlers — Phase 10.4."""
from __future__ import annotations

from uuid import UUID

from sqlalchemy.ext.asyncio import AsyncSession

from app.schemas.pricing import (
    BundleCreate,
    BundleUpdate,
    CapabilityCreate,
    CapabilityUpdate,
    PricingRuleCreate,
    PricingRuleUpdate,
)
from app.services.pricing import BundleService, CapabilityService, PricingRuleService
from shared.security import CurrentUser


class PricingCommands:
    def __init__(self, session: AsyncSession) -> None:
        self.rules = PricingRuleService(session)
        self.capabilities = CapabilityService(session)
        self.bundles = BundleService(session)

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

    async def update_rule(
        self, tenant_id: UUID, rule_id: UUID, body: PricingRuleUpdate, *, actor: CurrentUser | None
    ):
        return await self.rules.update(tenant_id, rule_id, body, actor=actor)

    async def delete_rule(
        self, tenant_id: UUID, rule_id: UUID, *, actor: CurrentUser | None
    ):
        return await self.rules.soft_delete(tenant_id, rule_id, actor=actor)

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

    async def update_capability(
        self, tenant_id: UUID, cap_id: UUID, body: CapabilityUpdate, *, actor: CurrentUser | None
    ):
        return await self.capabilities.update(tenant_id, cap_id, body, actor=actor)

    async def delete_capability(
        self, tenant_id: UUID, cap_id: UUID, *, actor: CurrentUser | None
    ):
        return await self.capabilities.soft_delete(tenant_id, cap_id, actor=actor)

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

    async def update_bundle(
        self, tenant_id: UUID, bundle_id: UUID, body: BundleUpdate, *, actor: CurrentUser | None
    ):
        return await self.bundles.update(tenant_id, bundle_id, body, actor=actor)

    async def delete_bundle(
        self, tenant_id: UUID, bundle_id: UUID, *, actor: CurrentUser | None
    ):
        return await self.bundles.soft_delete(tenant_id, bundle_id, actor=actor)
