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

from datetime import datetime
from typing import Optional
from uuid import UUID

from pydantic import BaseModel, Field

from app.models.jira_link import JiraLinkEntityType, JiraSyncDirection


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


class JiraLinkOut(BaseModel):
    id: UUID
    entity_type: JiraLinkEntityType
    entity_id: UUID
    jira_issue_key: str
    jira_issue_id: Optional[str] = None
    jira_project_key: Optional[str] = None
    jira_status: Optional[str] = None
    jira_priority: Optional[str] = None
    jira_assignee: Optional[str] = None
    jira_story_points: Optional[str] = None
    last_synced_at: Optional[datetime] = None
    created_at: datetime

    class Config:
        from_attributes = True


class JiraIssueSearch(BaseModel):
    query: str


class JiraIssueResult(BaseModel):
    issue_key: str
    summary: str
    status: str
    assignee: Optional[str] = None
    priority: Optional[str] = None
