//! Model management — delegates to agent crate.

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

pub use agent::model::model_entry::{CreateModelRequest, ModelResponse, UpdateModelRequest};

impl AppService {
    pub async fn agent_model_list(
        &self,
        provider_id: Option<Uuid>,
        _ctx: &Session,
    ) -> Result<Vec<agent::model::model_entry::ModelResponse>, AppError> {
        Ok(agent::model::model_entry::list_models(&self.db, provider_id).await?)
    }

    pub async fn agent_model_get(
        &self,
        id: Uuid,
        _ctx: &Session,
    ) -> Result<agent::model::model_entry::ModelResponse, AppError> {
        Ok(agent::model::model_entry::get_model(&self.db, id).await?)
    }

    pub async fn agent_model_create(
        &self,
        request: agent::model::model_entry::CreateModelRequest,
        ctx: &Session,
    ) -> Result<agent::model::model_entry::ModelResponse, AppError> {
        super::provider::require_system_caller(ctx)?;
        Ok(agent::model::model_entry::create_model(&self.db, request).await?)
    }

    pub async fn agent_model_update(
        &self,
        id: Uuid,
        request: agent::model::model_entry::UpdateModelRequest,
        ctx: &Session,
    ) -> Result<agent::model::model_entry::ModelResponse, AppError> {
        super::provider::require_system_caller(ctx)?;
        Ok(agent::model::model_entry::update_model(&self.db, id, request).await?)
    }

    pub async fn agent_model_delete(
        &self,
        id: Uuid,
        ctx: &Session,
    ) -> Result<(), AppError> {
        super::provider::require_system_caller(ctx)?;
        Ok(agent::model::model_entry::delete_model(&self.db, id).await?)
    }
}
