// Copyright 2025 The Drasi Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//! FFI layer for cdylib dynamic plugin loading.
//!
//! This module provides the `#[repr(C)]` types, vtable structs, and vtable
//! generation functions needed to wrap DrasiLib `Source`/`Reaction`/`BootstrapProvider`
//! trait implementations into stable C ABI entry points for cross-cdylib communication.
//!
//! # Module Structure
//!
//! - [`types`] — Core FFI-safe primitives (FfiStr, FfiResult, enums, etc.)
//! - [`callbacks`] — Log and lifecycle callback types
//! - [`vtables`] — `#[repr(C)]` vtable structs for all component types
//! - [`metadata`] — Plugin metadata for version validation at load time
//! - [`state_store_proxy`] — Plugin-side `StateStoreProvider` impl over vtable
//! - [`bootstrap_proxy`] — Plugin-side `BootstrapProvider` impl over vtable
//! - [`vtable_gen`] — Functions that wrap trait impls into vtables

pub mod bootstrap_proxy;
pub mod callbacks;
pub mod identity;
pub mod identity_proxy;
pub mod metadata;
pub mod payload;
pub mod secret_store;
pub mod snapshot_fetcher_proxy;
pub mod state_store_proxy;
pub mod tracing_bridge;
pub mod types;
pub mod vtable_gen;
pub mod vtables;
pub mod wal_provider_proxy;

// Re-export commonly used types at the ffi module level
pub use callbacks::{
    ConfigResolverFn, FfiLifecycleEvent, FfiLifecycleEventType, FfiLogEntry, FfiLogLevel,
    FfiLogLevelFilter, LifecycleCallbackFn, LogCallbackFn,
};
pub use metadata::{
    PluginMetadata, BUILD_TIMESTAMP, FFI_SDK_VERSION, GIT_COMMIT_SHA, TARGET_TRIPLE,
};
pub use payload::{BootstrapEventPayload, SourceEventPayload};
pub use types::{
    catch_panic_ffi, now_us, AsyncExecutorFn, FfiChangeOp, FfiComponentStatus, FfiCreateResult,
    FfiDispatchMode, FfiGetResult, FfiOwnedStr, FfiResult, FfiStr, FfiStringArray, SendMutPtr,
    SendPtr,
};
pub use vtable_gen::{
    build_bootstrap_plugin_vtable, build_bootstrap_provider_vtable,
    build_identity_provider_plugin_vtable, build_identity_provider_vtable_from_boxed,
    build_reaction_plugin_vtable, build_reaction_vtable, build_reaction_vtable_from_boxed,
    build_secret_store_plugin_vtable, build_secret_store_vtable_from_boxed,
    build_source_plugin_vtable, build_source_vtable, build_source_vtable_from_boxed,
    current_instance_log_ctx, InstanceLogContext,
};
pub use vtables::{
    BootstrapPluginVtable, BootstrapProviderVtable, FfiBootstrapContext, FfiBootstrapEvent,
    FfiBootstrapFetchOutboxFn, FfiBootstrapFetchSnapshotFn, FfiBootstrapPushCallbackFn,
    FfiBootstrapReadCheckpointFn, FfiBootstrapReceiver, FfiBootstrapResult,
    FfiBootstrapResultCallbackFn, FfiBootstrapResultReceiver, FfiBootstrapSender,
    FfiBootstrapWriteCheckpointFn, FfiChangePushCallbackFn, FfiChangeReceiver, FfiCheckpoint,
    FfiCheckpointResult, FfiOutboxIterator, FfiOutboxIteratorResponse, FfiPluginRegistration,
    FfiQueryResult, FfiResultPushCallbackFn, FfiRuntimeContext, FfiSnapshotIterator,
    FfiSnapshotIteratorResponse, FfiSourceEvent, FfiSubscriptionResponse,
    IdentityProviderPluginVtable, ReactionPluginVtable, ReactionVtable, SecretStorePluginVtable,
    SnapshotFetcherVtable, SourcePluginVtable, SourceVtable, StateStoreVtable, WalProviderVtable,
};

pub use bootstrap_proxy::FfiBootstrapProviderProxy;
pub use identity::{
    credentials_to_ffi, FfiCredentialType, FfiCredentials, FfiCredentialsResult,
    IdentityProviderVtable,
};
pub use identity_proxy::FfiIdentityProviderProxy;
pub use secret_store::{FfiGetSecretResult, SecretStoreProviderVtable};
pub use snapshot_fetcher_proxy::FfiSnapshotFetcherProxy;
pub use state_store_proxy::FfiStateStoreProxy;
pub use wal_provider_proxy::FfiWalProviderProxy;
