//! Model version management — delegates to agent crate.

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

pub use agent::model::version::{CreateModelVersionRequest, ModelVersionResponse, UpdateModelVersionRequest};

impl AppService {
    pub async fn agent_model_version_list(
        &self,
        model_id: Option<Uuid>,
        _ctx: &Session,
    ) -> Result<Vec<agent::model::version::ModelVersionResponse>, AppError> {
        Ok(agent::model::version::list_versions(&self.db, model_id).await?)
    }

    pub async fn agent_model_version_get(
        &self,
        id: Uuid,
        _ctx: &Session,
    ) -> Result<agent::model::version::ModelVersionResponse, AppError> {
        Ok(agent::model::version::get_version(&self.db, id).await?)
    }

    pub async fn agent_model_version_create(
        &self,
        request: agent::model::version::CreateModelVersionRequest,
        ctx: &Session,
    ) -> Result<agent::model::version::ModelVersionResponse, AppError> {
        super::provider::require_system_caller(ctx)?;
        Ok(agent::model::version::create_version(&self.db, request).await?)
    }

    pub async fn agent_model_version_update(
        &self,
        id: Uuid,
        request: agent::model::version::UpdateModelVersionRequest,
        ctx: &Session,
    ) -> Result<agent::model::version::ModelVersionResponse, AppError> {
        super::provider::require_system_caller(ctx)?;
        Ok(agent::model::version::update_version(&self.db, id, request).await?)
    }

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