//! Capability management — delegates to agent crate.

use crate::AppService;
use crate::error::AppError;
use session::Session;

pub use agent::model::capability::{CreateModelCapabilityRequest, ModelCapabilityResponse, UpdateModelCapabilityRequest};

impl AppService {
    pub async fn agent_model_capability_list(
        &self,
        model_version_id: i64,
        _ctx: &Session,
    ) -> Result<Vec<agent::model::capability::ModelCapabilityResponse>, AppError> {
        Ok(agent::model::capability::list_capabilities(&self.db, model_version_id).await?)
    }

    pub async fn agent_model_capability_get(
        &self,
        id: i64,
        _ctx: &Session,
    ) -> Result<agent::model::capability::ModelCapabilityResponse, AppError> {
        Ok(agent::model::capability::get_capability(&self.db, id).await?)
    }

    pub async fn agent_model_capability_create(
        &self,
        request: agent::model::capability::CreateModelCapabilityRequest,
        ctx: &Session,
    ) -> Result<agent::model::capability::ModelCapabilityResponse, AppError> {
        super::provider::require_system_caller(ctx)?;
        Ok(agent::model::capability::create_capability(&self.db, request).await?)
    }

    pub async fn agent_model_capability_update(
        &self,
        id: i64,
        request: agent::model::capability::UpdateModelCapabilityRequest,
        ctx: &Session,
    ) -> Result<agent::model::capability::ModelCapabilityResponse, AppError> {
        super::provider::require_system_caller(ctx)?;
        Ok(agent::model::capability::update_capability(&self.db, id, request).await?)
    }

    pub async fn agent_model_capability_delete(
        &self,
        id: i64,
        ctx: &Session,
    ) -> Result<(), AppError> {
        super::provider::require_system_caller(ctx)?;
        Ok(agent::model::capability::delete_capability(&self.db, id).await?)
    }
}
