"""Collaborator Model.""" from datetime import datetime from typing import Optional from sqlalchemy import Enum, ForeignKey from sqlalchemy.orm import Mapped, mapped_column from sqlalchemy.sql import func from collaborator.connectors import mysql from collaborator.constants.collaborator import CollaboratorType class Collaborator(mysql.BaseModel): """Encapsulates collaborator data. Represents collaborator table in the collaborator database. """ __tablename__ = "collaborator" collaborator_id: Mapped[int] = mapped_column("id", primary_key=True) name: Mapped[str] vendor_id: Mapped[int] subaccount_id: Mapped[Optional[int]] participant_id: Mapped[Optional[str]] performance_rights: Mapped[Optional[bool]] = mapped_column(default=True) recipient_id: Mapped[Optional[int]] = mapped_column(ForeignKey("recipient.id")) currency: Mapped[Optional[str]] collaborator_type: Mapped[Optional[CollaboratorType]] = mapped_column( Enum(CollaboratorType), default=CollaboratorType.COLLABORATOR ) description: Mapped[Optional[str]] internal_id: Mapped[Optional[str]] created_date: Mapped[Optional[datetime]] = mapped_column(default=func.now()) created_by: Mapped[Optional[str]] updated_date: Mapped[Optional[datetime]] updated_by: Mapped[Optional[str]] dp_enabled_date: Mapped[Optional[datetime]] dp_splits_agreed_date: Mapped[Optional[datetime]] def to_dict(self) -> dict: """Collaborator data dictionary. Returns: dict """ return { "id": self.collaborator_id, "name": self.name, "vendor_id": self.vendor_id, "subaccount_id": self.subaccount_id, "participant_id": self.participant_id, "performance_rights": self.performance_rights, "recipient_id": self.recipient_id, "currency": self.currency, "collaborator_type": self.collaborator_type, "description": self.description, "internal_id": self.internal_id, "created_date": ( self.created_date.isoformat() if self.created_date else None ), "dp_enabled_date": ( self.dp_enabled_date.isoformat() if self.dp_enabled_date else None ), "dp_splits_agreed_date": ( self.dp_splits_agreed_date.isoformat() if self.dp_splits_agreed_date else None ), }