//! Serializable types for the blob domain.

use serde::{Deserialize, Serialize};

use crate::commit::types::CommitOid;

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BlobInfo {
    pub oid: CommitOid,
    pub size: usize,
    pub is_binary: bool,
}

impl BlobInfo {
    pub fn from_git2(blob: &git2::Blob<'_>) -> Self {
        Self {
            oid: CommitOid::from_git2(blob.id()),
            size: blob.size(),
            is_binary: blob.is_binary(),
        }
    }
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BlobContent {
    pub oid: CommitOid,
    pub size: usize,
    pub is_binary: bool,
    pub content: Vec<u8>,
}

impl BlobContent {
    pub fn from_git2(blob: &git2::Blob<'_>) -> Self {
        Self {
            oid: CommitOid::from_git2(blob.id()),
            size: blob.size(),
            is_binary: blob.is_binary(),
            content: blob.content().to_vec(),
        }
    }
}
