from typing import Optional, Self from pydantic import UUID4, BaseModel, model_validator from pdp.fastapi.schemas.tenant import Tenant class TenantOwnedResourceAttributes(BaseModel): """Attributes for a resource that belongs to a Tenant.""" tenant: Tenant class IdentityOwnedResourceAttributes(BaseModel): """Attributes for a resource that belongs to an Identity""" identity_uuid: UUID4 class IdentityAndTenantOwnedResourceAttributes(BaseModel): """Attributes for a resource that belongs to an Identity and Tenant.""" tenant: Optional[Tenant] = None identity_uuid: Optional[UUID4] = None @model_validator(mode="after") def validate_at_least_one_attribute_is_present(self) -> Self: """Validate either tenant or identity_uuid are set.""" if not self.tenant and not self.identity_uuid: raise ValueError("Either tenant or identity_uuid must be set.") return self