"""Pydantic schemas for Jira integration endpoints."""

# Import datetime from datetime
from datetime import datetime

# Import Optional from typing
from typing import Optional

# Import UUID from uuid
from uuid import UUID

# Import BaseModel, Field from pydantic
from pydantic import BaseModel, Field

# Import JiraLinkEntityType, JiraSyncDirection from app.models.jira_link
from app.models.jira_link import JiraLinkEntityType, JiraSyncDirection


# Define class JiraLinkCreate
class JiraLinkCreate(BaseModel):
    """Payload for linking an Aegis entity to an existing Jira issue."""

    # entity_type: JiraLinkEntityType
    entity_type: JiraLinkEntityType
    # entity_id: UUID
    entity_id: UUID
    # Assign jira_issue_key = Field(..., pattern=r"^[A-Z][A-Z0-9]+-\d+$")
    jira_issue_key: str = Field(..., pattern=r"^[A-Z][A-Z0-9]+-\d+$")
    # Assign sync_direction = JiraSyncDirection.bidirectional
    sync_direction: JiraSyncDirection = JiraSyncDirection.bidirectional


# Define class JiraLinkOut
class JiraLinkOut(BaseModel):
    """Full representation of a Jira link returned by the API."""

    # id: UUID
    id: UUID
    # entity_type: JiraLinkEntityType
    entity_type: JiraLinkEntityType
    # entity_id: UUID
    entity_id: UUID
    # jira_issue_key: str
    jira_issue_key: str
    # Assign jira_issue_id = None
    jira_issue_id: Optional[str] = None
    # Assign jira_project_key = None
    jira_project_key: Optional[str] = None
    # Assign jira_status = None
    jira_status: Optional[str] = None
    # Assign jira_priority = None
    jira_priority: Optional[str] = None
    # Assign jira_assignee = None
    jira_assignee: Optional[str] = None
    # Assign jira_story_points = None
    jira_story_points: Optional[str] = None
    # Assign last_synced_at = None
    last_synced_at: Optional[datetime] = None
    # created_at: datetime
    created_at: datetime

    # Define class Config
    class Config:
        """ORM mode configuration for SQLAlchemy model mapping."""

        # Assign from_attributes = True
        from_attributes = True


# Define class JiraIssueSearch
class JiraIssueSearch(BaseModel):
    """Payload for searching Jira issues by free-text query."""

    # query: str
    query: str


# Define class JiraIssueResult
class JiraIssueResult(BaseModel):
    """Lightweight Jira issue representation returned by search results."""

    # issue_key: str
    issue_key: str
    # summary: str
    summary: str
    # status: str
    status: str
    # Assign assignee = None
    assignee: Optional[str] = None
    # Assign priority = None
    priority: Optional[str] = None
