# [DEF:backend.src.api.routes.git_schemas:Module]
#
# @TIER:      STANDARD
# @SEMANTICS: git, schemas, pydantic, api, contracts
# @PURPOSE:   Defines Pydantic models for the Git integration API layer.
# @LAYER:     API
# @RELATION:  DEPENDS_ON -> backend.src.models.git
#
# @INVARIANT: All schemas must be compatible with the FastAPI router.

from pydantic import BaseModel, Field
from typing import List, Optional
from datetime import datetime
from uuid import UUID
from src.models.git import GitProvider, GitStatus, SyncStatus

# [DEF:GitServerConfigBase:Class]
# @TIER: TRIVIAL
# @PURPOSE: Base schema for Git server configuration attributes.
class GitServerConfigBase(BaseModel):
    name: str = Field(..., description="Display name for the Git server")
    provider: GitProvider = Field(..., description="Git provider (GITHUB, GITLAB, GITEA)")
    url: str = Field(..., description="Server base URL")
    pat: str = Field(..., description="Personal Access Token")
    default_repository: Optional[str] = Field(None, description="Default repository path (org/repo)")
# [/DEF:GitServerConfigBase:Class]

# [DEF:GitServerConfigCreate:Class]
# @PURPOSE: Schema for creating a new Git server configuration.
class GitServerConfigCreate(GitServerConfigBase):
    """Schema for creating a new Git server configuration."""
    pass
# [/DEF:GitServerConfigCreate:Class]

# [DEF:GitServerConfigSchema:Class]
# @PURPOSE: Schema for representing a Git server configuration with metadata.
class GitServerConfigSchema(GitServerConfigBase):
    """Schema for representing a Git server configuration with metadata."""
    id: str
    status: GitStatus
    last_validated: datetime

    class Config:
        from_attributes = True
# [/DEF:GitServerConfigSchema:Class]

# [DEF:GitRepositorySchema:Class]
# @PURPOSE: Schema for tracking a local Git repository linked to a dashboard.
class GitRepositorySchema(BaseModel):
    """Schema for tracking a local Git repository linked to a dashboard."""
    id: str
    dashboard_id: int
    config_id: str
    remote_url: str
    local_path: str
    current_branch: str
    sync_status: SyncStatus

    class Config:
        from_attributes = True
# [/DEF:GitRepositorySchema:Class]

# [DEF:BranchSchema:Class]
# @PURPOSE: Schema for representing a Git branch metadata.
class BranchSchema(BaseModel):
    """Schema for representing a Git branch."""
    name: str
    commit_hash: str
    is_remote: bool
    last_updated: datetime
# [/DEF:BranchSchema:Class]

# [DEF:CommitSchema:Class]
# @PURPOSE: Schema for representing Git commit details.
class CommitSchema(BaseModel):
    """Schema for representing a Git commit."""
    hash: str
    author: str
    email: str
    timestamp: datetime
    message: str
    files_changed: List[str]
# [/DEF:CommitSchema:Class]

# [DEF:BranchCreate:Class]
# @PURPOSE: Schema for branch creation requests.
class BranchCreate(BaseModel):
    """Schema for branch creation requests."""
    name: str
    from_branch: str
# [/DEF:BranchCreate:Class]

# [DEF:BranchCheckout:Class]
# @PURPOSE: Schema for branch checkout requests.
class BranchCheckout(BaseModel):
    """Schema for branch checkout requests."""
    name: str
# [/DEF:BranchCheckout:Class]

# [DEF:CommitCreate:Class]
# @PURPOSE: Schema for staging and committing changes.
class CommitCreate(BaseModel):
    """Schema for staging and committing changes."""
    message: str
    files: List[str]
# [/DEF:CommitCreate:Class]

# [DEF:ConflictResolution:Class]
# @PURPOSE: Schema for resolving merge conflicts.
class ConflictResolution(BaseModel):
    """Schema for resolving merge conflicts."""
    file_path: str
    resolution: str = Field(pattern="^(mine|theirs|manual)$")
    content: Optional[str] = None
# [/DEF:ConflictResolution:Class]

# [DEF:DeploymentEnvironmentSchema:Class]
# @PURPOSE: Schema for representing a target deployment environment.
class DeploymentEnvironmentSchema(BaseModel):
    """Schema for representing a target deployment environment."""
    id: str
    name: str
    superset_url: str
    is_active: bool

    class Config:
        from_attributes = True
# [/DEF:DeploymentEnvironmentSchema:Class]

# [DEF:DeployRequest:Class]
# @PURPOSE: Schema for dashboard deployment requests.
class DeployRequest(BaseModel):
    """Schema for deployment requests."""
    environment_id: str
# [/DEF:DeployRequest:Class]

# [DEF:RepoInitRequest:Class]
# @PURPOSE: Schema for repository initialization requests.
class RepoInitRequest(BaseModel):
    """Schema for repository initialization requests."""
    config_id: str
    remote_url: str
# [/DEF:RepoInitRequest:Class]

# [/DEF:backend.src.api.routes.git_schemas:Module]