"""Contact Database Tables/Models.

Models of the Endorser tables for Contacts (Authors) and related data.

"""
import uuid
from datetime import datetime
from typing import List

from sqlmodel import Field
from sqlalchemy import Column, func, text, String
from sqlalchemy.dialects.postgresql import UUID, TIMESTAMP, ARRAY

from api.db.models.base import BaseModel


class Contact(BaseModel, table=True):
    """Contact.

    This is the model for the Contact table (postgresql specific dialects in use).

    Attributes:
      contact_id: Endorser's Contact ID
      author_status: Whether they are an approved author or not
      endorse_status: Whether endorsements are auto-approved or not
      tags: Set by endorser for arbitrary grouping of Contacts
      connection_id: Underlying AcaPy connection id
      connection_alias: Underlying AcaPy connection alias
      public_did: Represents the Contact's agent's Public DID (if any)
      state: The underlying AcaPy connection state
      created_at: Timestamp when record was created
      updated_at: Timestamp when record was last modified
    """

    contact_id: uuid.UUID = Field(
        sa_column=Column(
            UUID(as_uuid=True),
            primary_key=True,
            server_default=text("gen_random_uuid()"),
        )
    )

    author_status: str = Field(nullable=False)
    endorse_status: str = Field(nullable=False)
    tags: List[str] = Field(sa_column=Column(ARRAY(String)))

    # acapy data ---
    connection_id: uuid.UUID = Field(nullable=False)
    connection_protocol: str = Field(nullable=False)
    connection_alias: str = Field(nullable=True, default=False)
    public_did: str = Field(nullable=True, default=False)
    state: str = Field(nullable=False)
    # --- acapy data

    created_at: datetime = Field(
        sa_column=Column(TIMESTAMP, nullable=False, server_default=func.now())
    )
    updated_at: datetime = Field(
        sa_column=Column(
            TIMESTAMP, nullable=False, server_default=func.now(), onupdate=func.now()
        )
    )

sqlalchemy.func.now sqlmodel.Field sqlalchemy.dialects.postgresql.ARRAY sqlalchemy.dialects.postgresql.UUID sqlalchemy.text
[((1326, 1347), 'sqlmodel.Field', 'Field', ([], {'nullable': '(False)'}), '(nullable=False)\n', (1331, 1347), False, 'from sqlmodel import Field\n'), ((1374, 1395), 'sqlmodel.Field', 'Field', ([], {'nullable': '(False)'}), '(nullable=False)\n', (1379, 1395), False, 'from sqlmodel import Field\n'), ((1510, 1531), 'sqlmodel.Field', 'Field', ([], {'nullable': '(False)'}), '(nullable=False)\n', (1515, 1531), False, 'from sqlmodel import Field\n'), ((1563, 1584), 'sqlmodel.Field', 'Field', ([], {'nullable': '(False)'}), '(nullable=False)\n', (1568, 1584), False, 'from sqlmodel import Field\n'), ((1613, 1648), 'sqlmodel.Field', 'Field', ([], {'nullable': '(True)', 'default': '(False)'}), '(nullable=True, default=False)\n', (1618, 1648), False, 'from sqlmodel import Field\n'), ((1671, 1706), 'sqlmodel.Field', 'Field', ([], {'nullable': '(True)', 'default': '(False)'}), '(nullable=True, default=False)\n', (1676, 1706), False, 'from sqlmodel import Field\n'), ((1724, 1745), 'sqlmodel.Field', 'Field', ([], {'nullable': '(False)'}), '(nullable=False)\n', (1729, 1745), False, 'from sqlmodel import Field\n'), ((1180, 1198), 'sqlalchemy.dialects.postgresql.UUID', 'UUID', ([], {'as_uuid': '(True)'}), '(as_uuid=True)\n', (1184, 1198), False, 'from sqlalchemy.dialects.postgresql import UUID, TIMESTAMP, ARRAY\n'), ((1441, 1454), 'sqlalchemy.dialects.postgresql.ARRAY', 'ARRAY', (['String'], {}), '(String)\n', (1446, 1454), False, 'from sqlalchemy.dialects.postgresql import UUID, TIMESTAMP, ARRAY\n'), ((1257, 1282), 'sqlalchemy.text', 'text', (['"""gen_random_uuid()"""'], {}), "('gen_random_uuid()')\n", (1261, 1282), False, 'from sqlalchemy import Column, func, text, String\n'), ((1869, 1879), 'sqlalchemy.func.now', 'func.now', ([], {}), '()\n', (1877, 1879), False, 'from sqlalchemy import Column, func, text, String\n'), ((2001, 2011), 'sqlalchemy.func.now', 'func.now', ([], {}), '()\n', (2009, 2011), False, 'from sqlalchemy import Column, func, text, String\n'), ((2022, 2032), 'sqlalchemy.func.now', 'func.now', ([], {}), '()\n', (2030, 2032), False, 'from sqlalchemy import Column, func, text, String\n')]