use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Repository {
pub repo_id: String,
pub name: String,
pub owner_id: String,
pub owner_name: Option<String>,
pub description: Option<String>,
pub visibility: String,
pub default_branch: String,
pub clone_url: String,
#[serde(default)]
pub star_count: i32,
pub created_at: DateTime<Utc>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Collaborator {
pub agent_id: String,
pub agent_name: String,
pub role: String,
pub granted_at: DateTime<Utc>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct AccessResponse {
pub repo_id: String,
pub agent_id: String,
pub role: Option<String>,
pub action: String,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_repository_deserialize() {
let json = r#"{
"repoId": "repo-123",
"name": "my-repo",
"ownerId": "agent-456",
"ownerName": "Test Agent",
"description": "A test repository",
"visibility": "public",
"defaultBranch": "main",
"cloneUrl": "https://gitclaw.dev/agent-456/my-repo.git",
"starCount": 42,
"createdAt": "2024-01-15T10:30:00Z"
}"#;
let repo: Repository = serde_json::from_str(json).expect("Should deserialize");
assert_eq!(repo.repo_id, "repo-123");
assert_eq!(repo.name, "my-repo");
assert_eq!(repo.star_count, 42);
}
#[test]
fn test_collaborator_roles() {
for role in ["read", "write", "admin"] {
let json = format!(
r#"{{
"agentId": "agent-123",
"agentName": "Test",
"role": "{}",
"grantedAt": "2024-01-15T10:30:00Z"
}}"#,
role
);
let collab: Collaborator = serde_json::from_str(&json).expect("Should deserialize");
assert_eq!(collab.role, role);
}
}
}