use serde::{Deserialize, Serialize};
use uuid::Uuid;

use crate::issues::types::{IssueAuthor, LabelResponse};

#[derive(Debug, Clone, Serialize, Deserialize, utoipa::ToSchema)]
pub struct PullRequestResponse {
    pub number: i64,
    pub title: String,
    pub body: Option<String>,
    pub state: String,
    pub draft: bool,
    pub author: IssueAuthor,
    #[schema(value_type = String)]
    pub source_repo: Uuid,
    pub source_branch: String,
    pub source_sha: String,
    pub target_branch: String,
    pub target_sha: String,
    pub merged_by: Option<IssueAuthor>,
    #[schema(value_type = Option<String>)]
    pub merged_at: Option<chrono::DateTime<chrono::Utc>>,
    pub closed_by: Option<IssueAuthor>,
    #[schema(value_type = Option<String>)]
    pub closed_at: Option<chrono::DateTime<chrono::Utc>>,
    #[schema(value_type = String)]
    pub created_at: chrono::DateTime<chrono::Utc>,
    #[schema(value_type = String)]
    pub updated_at: chrono::DateTime<chrono::Utc>,
    pub labels: Vec<LabelResponse>,
    pub assignees: Vec<IssueAuthor>,
    pub reviews: Vec<PullRequestReviewResponse>,
}

#[derive(Debug, Clone, Serialize, Deserialize, utoipa::ToSchema)]
pub struct PullRequestCommentResponse {
    #[schema(value_type = String)]
    pub id: Uuid,
    pub author: IssueAuthor,
    pub body: String,
    #[schema(value_type = String)]
    pub created_at: chrono::DateTime<chrono::Utc>,
    #[schema(value_type = String)]
    pub updated_at: chrono::DateTime<chrono::Utc>,
}

#[derive(Debug, Clone, Serialize, Deserialize, utoipa::ToSchema)]
pub struct PullRequestReviewResponse {
    #[schema(value_type = String)]
    pub id: Uuid,
    pub reviewer: IssueAuthor,
    pub state: String,
    pub body: Option<String>,
    pub commit_sha: Option<String>,
    #[schema(value_type = Option<String>)]
    pub submitted_at: Option<chrono::DateTime<chrono::Utc>>,
    #[schema(value_type = String)]
    pub created_at: chrono::DateTime<chrono::Utc>,
}

#[derive(Debug, Clone, Serialize, Deserialize, utoipa::ToSchema)]
pub struct PullRequestReviewCommentResponse {
    #[schema(value_type = String)]
    pub id: Uuid,
    pub author: IssueAuthor,
    pub path: String,
    pub line: Option<i32>,
    pub body: String,
    pub commit_sha: String,
    pub resolved: bool,
    #[schema(value_type = String)]
    pub created_at: chrono::DateTime<chrono::Utc>,
    #[schema(value_type = String)]
    pub updated_at: chrono::DateTime<chrono::Utc>,
}

#[derive(Debug, Clone, Serialize, Deserialize, utoipa::ToSchema)]
pub struct PullRequestReactionResponse {
    #[schema(value_type = String)]
    pub id: Uuid,
    pub user: IssueAuthor,
    pub reaction: String,
    #[schema(value_type = String)]
    pub created_at: chrono::DateTime<chrono::Utc>,
}

#[derive(Debug, Clone, Deserialize, utoipa::IntoParams)]
pub struct PullRequestFilter {
    pub state: Option<String>,
    pub author: Option<String>,
    pub assignee: Option<String>,
    pub label: Option<String>,
}
