use pylon_plugin::{Plugin, PluginError, PluginContext, PluginRoute, RequestMeta};
use pylon_auth::AuthContext;
use serde_json::Value;
pub trait Plugin: Send + Sync {
/// Unique name for this plugin.
fn name(&self) -> &str;
/// Called once when the plugin is registered.
fn on_init(&self, _ctx: &PluginContext) {}
/// Custom API routes this plugin handles.
fn routes(&self) -> Vec<PluginRoute> { vec![] }
/// Before an entity insert. Mutate `data` in place; return Err to reject.
fn before_insert(&self, _entity: &str, _data: &mut Value, _auth: &AuthContext)
-> Result<(), PluginError> { Ok(()) }
fn after_insert(&self, _entity: &str, _id: &str, _data: &Value, _auth: &AuthContext) {}
/// Before an entity update. Mutate `data`; return Err to reject.
fn before_update(&self, _entity: &str, _id: &str, _data: &mut Value, _auth: &AuthContext)
-> Result<(), PluginError> { Ok(()) }
fn after_update(&self, _entity: &str, _id: &str, _data: &Value, _auth: &AuthContext) {}
/// Before an entity delete. Return Err to reject.
fn before_delete(&self, _entity: &str, _id: &str, _auth: &AuthContext)
-> Result<(), PluginError> { Ok(()) }
fn after_delete(&self, _entity: &str, _id: &str, _auth: &AuthContext) {}
/// On every incoming request (middleware). Return Err to short-circuit.
fn on_request(&self, _method: &str, _path: &str, _auth: &AuthContext)
-> Result<(), PluginError> { Ok(()) }
/// Richer variant with per-request metadata (peer IP today).
/// Defaults to delegating to `on_request`.
fn on_request_with_meta(&self, method: &str, path: &str, auth: &AuthContext,
_meta: &RequestMeta<'_>) -> Result<(), PluginError> {
self.on_request(method, path, auth)
}
/// When a new session is created.
fn on_session_create(&self, _user_id: &str, _token: &str) {}
/// Additional manifest entities this plugin contributes.
fn entities(&self) -> Vec<pylon_kernel::ManifestEntity> { vec![] }
}