from psycopg import Connection
from src.__types.index import Tenant
from src.domain.services.tenant_service import TenantService
from src.infrastructure.credential_manager import CredentialManager


class TenantUseCase:
    def __init__(
        self,
        tenant_service: TenantService,
    ) -> None:
        self.tenant_service = tenant_service

    @classmethod
    def create(
        cls,
        connection: Connection,
        credential_manager: CredentialManager,
    ) -> "TenantUseCase":
        return TenantUseCase(
            tenant_service=TenantService.create(
                connection=connection,
                credential_manager=credential_manager,
            ),
        )

    def issue(
        self,
        legal_name: str,
        name: str | None,
        whi_customer_ids: list[str],
        cydas_customer_ids: list[str],
    ) -> Tenant:
        """Tenant発行 (Application Client作成・Tenant追加) を行う。"""
        return self.tenant_service.issue(
            legal_name=legal_name,
            name=name,
            whi_customer_ids=whi_customer_ids,
            cydas_customer_ids=cydas_customer_ids,
        )
