mod proof_log;
mod storage;

pub use proof_log::SolanaProofLogAdaptor;
#[cfg(feature = "solana-proof-log-rpc")]
pub use proof_log::{PublicRpcSolanaProofLogAdaptor, PublicRpcSolanaProofLogConfig};
pub use storage::DeterministicS3StorageAdaptor;

use crate::envelope::PublishEnvelope;
use crate::error::TrazaeoResult;
use crate::proof_log::{ProofLogCommitment, ProofLogPublishResult};
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct StoredObject {
    pub key: String,
    pub uri: String,
    pub content_hash: String,
    pub byte_length: usize,
    pub content_type: String,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct S3KeyParams {
    pub bucket: String,
    pub base_prefix: Option<String>,
    pub object_name: String,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct S3PutRequest {
    pub key: String,
    pub bytes: Vec<u8>,
    pub content_type: String,
}

pub trait StorageAdaptor {
    fn put_bytes(&self, request: &S3PutRequest) -> TrazaeoResult<StoredObject>;
}

pub trait ProofLogAdaptor {
    fn log_publish_proof(
        &self,
        envelope: &PublishEnvelope,
        committed_at: &str,
        committed_unix_seconds: i64,
        prev_entry_hash: [u8; 32],
    ) -> TrazaeoResult<ProofLogPublishResult>;

    fn verify_publish_proof(
        &self,
        envelope: &PublishEnvelope,
        commitment: &ProofLogCommitment,
    ) -> TrazaeoResult<()>;
}

#[cfg(test)]
mod tests;
