//! Parameter types for project store operations.

use serde::{Deserialize, Serialize};
use std::path::PathBuf;
use uuid::Uuid;

/// Parameters for creating a new project.
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct CreateProjectParams {
    /// Human-readable project name
    pub name: String,
    /// Project description
    #[serde(default)]
    pub description: String,
    /// Optional icon (emoji or abbreviation)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub icon: Option<String>,
    /// Owner user ID
    pub owner: Uuid,
    /// Initial tags
    #[serde(default)]
    pub tags: Vec<String>,
    /// Initial languages
    #[serde(default)]
    pub languages: Vec<String>,
    /// Arbitrary metadata
    #[serde(default)]
    pub metadata: serde_json::Value,
}

/// Filter for listing projects.
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
pub struct ProjectFilter {
    /// Filter by owner
    #[serde(skip_serializing_if = "Option::is_none")]
    pub owner: Option<Uuid>,
    /// Filter by tag (project must have all specified tags)
    #[serde(default)]
    pub tags: Vec<String>,
    /// Filter by name substring (case-insensitive)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub name_contains: Option<String>,
}

/// Fields to update on a project.
///
/// Only `Some` fields are applied; `None` fields are left unchanged.
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
pub struct ProjectUpdate {
    /// New name
    #[serde(skip_serializing_if = "Option::is_none")]
    pub name: Option<String>,
    /// New description
    #[serde(skip_serializing_if = "Option::is_none")]
    pub description: Option<String>,
    /// New icon
    #[serde(skip_serializing_if = "Option::is_none")]
    pub icon: Option<Option<String>>,
    /// New tags (replaces all)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub tags: Option<Vec<String>>,
    /// New languages (replaces all)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub languages: Option<Vec<String>>,
    /// New metadata (replaces all)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub metadata: Option<serde_json::Value>,
}

/// Parameters for adding a repository to a project.
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct AddRepositoryParams {
    /// Project to add the repository to
    pub project_id: Uuid,
    /// Local filesystem path
    pub path: PathBuf,
    /// Whether this is the primary repository
    #[serde(default)]
    pub is_primary: bool,
    /// Optional human-readable label
    #[serde(skip_serializing_if = "Option::is_none")]
    pub label: Option<String>,
}

/// Parameters for adding a worktree to a repository.
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct AddWorktreeParams {
    /// Repository this worktree belongs to
    pub repository_id: Uuid,
    /// Local filesystem path for the worktree
    pub path: PathBuf,
    /// Branch name
    pub branch: String,
    /// Optional work branch name
    #[serde(skip_serializing_if = "Option::is_none")]
    pub work_branch: Option<String>,
    /// Optional naming strategy
    #[serde(skip_serializing_if = "Option::is_none")]
    pub naming_strategy: Option<String>,
}

/// Fields to update on a worktree.
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
pub struct WorktreeUpdate {
    /// New branch
    #[serde(skip_serializing_if = "Option::is_none")]
    pub branch: Option<String>,
    /// New work branch
    #[serde(skip_serializing_if = "Option::is_none")]
    pub work_branch: Option<Option<String>>,
}

/// Parameters for creating a project binding.
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct BindParams {
    /// Project to bind
    pub project_id: Uuid,
    /// Optional connector ID
    #[serde(skip_serializing_if = "Option::is_none")]
    pub connector_id: Option<String>,
    /// Optional session ID
    #[serde(skip_serializing_if = "Option::is_none")]
    pub session_id: Option<Uuid>,
    /// Optional working directory override
    #[serde(skip_serializing_if = "Option::is_none")]
    pub working_dir: Option<PathBuf>,
}
