"""Git repository request/response schemas."""

import uuid
from datetime import datetime

from pydantic import BaseModel, ConfigDict


class GitRepositoryCreate(BaseModel):
    name: str
    remote_url: str | None = None
    force_original_url: bool = False
    ssh_key_id: str | None = None


class URLParseRequest(BaseModel):
    url: str


class URLParseResponse(BaseModel):
    original_url: str
    base_url: str | None
    is_valid_clone_url: bool
    needs_parsing: bool
    host: str | None
    message: str
    error_code: str | None


class GitRepositoryResponse(BaseModel):
    model_config = ConfigDict(from_attributes=True)

    id: uuid.UUID
    name: str
    path: str
    project_id: uuid.UUID | None
    owner_id: uuid.UUID
    is_mirror: bool
    remote_url: str | None
    last_push: datetime | None
    ssh_key_id: uuid.UUID | None
    created_at: datetime
    updated_at: datetime


class UpdateSSHKeyRequest(BaseModel):
    ssh_key_id: str | None = None


class FileListResponse(BaseModel):
    path: str
    branch: str
    entries: list[dict]


class FileContentResponse(BaseModel):
    path: str
    branch: str
    content: str
    size: int
    encoding: str
    language: str | None
    is_binary: bool
    last_commit: dict | None


class BranchesResponse(BaseModel):
    branches: list[dict]
    default_branch: str


class FileUpdateRequest(BaseModel):
    path: str
    branch: str
    content: str
    commit_message: str


class FileUpdateResponse(BaseModel):
    commit_hash: str
    message: str
    branch: str


class StatusResponse(BaseModel):
    branch: str
    modified: list[str]
    added: list[str]
    deleted: list[str]
    untracked: list[str]
    renamed: list[str]
    ahead: int
    behind: int


class BranchCreateRequest(BaseModel):
    name: str
    base_branch: str = "HEAD"


class CheckoutRequest(BaseModel):
    branch: str


class CommitRequest(BaseModel):
    message: str
    files: list[str] | None = None


class CommitResponse(BaseModel):
    commit_hash: str
    message: str


class FetchResponse(BaseModel):
    message: str


class PullResponse(BaseModel):
    message: str


class PushResponse(BaseModel):
    message: str


class MergeRequest(BaseModel):
    source_branch: str
    target_branch: str | None = None
    message: str | None = None


class MergeResponse(BaseModel):
    commit_hash: str
    message: str
