// SPDX-FileCopyrightText: Copyright (c) 2024-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

use super::*;
use llm_rs::model_card::ModelDeploymentCard as RsModelDeploymentCard;

#[pyclass]
#[derive(Clone)]
pub(crate) struct ModelDeploymentCard {
    pub(crate) inner: RsModelDeploymentCard,
}

#[pymethods]
impl ModelDeploymentCard {
    // Previously called "from_local_path"
    #[staticmethod]
    fn load(path: String, model_name: String) -> PyResult<ModelDeploymentCard> {
        let mut card = RsModelDeploymentCard::load_from_disk(&path, None).map_err(to_pyerr)?;
        card.set_name(&model_name);
        Ok(ModelDeploymentCard { inner: card })
    }

    #[staticmethod]
    fn from_json_str(json: String) -> PyResult<ModelDeploymentCard> {
        let card = RsModelDeploymentCard::load_from_json_str(&json).map_err(to_pyerr)?;
        Ok(ModelDeploymentCard { inner: card })
    }

    fn to_json_str(&self) -> PyResult<String> {
        let json = self.inner.to_json().map_err(to_pyerr)?;
        Ok(json)
    }

    fn source_path(&self) -> &str {
        self.inner.source_path()
    }

    fn name(&self) -> &str {
        self.inner.name()
    }

    fn model_type(&self) -> ModelType {
        ModelType {
            inner: self.inner.model_type,
        }
    }

    fn runtime_config(&self, py: Python<'_>) -> PyResult<PyObject> {
        let rc = pythonize::pythonize(py, &self.inner.runtime_config).map_err(to_pyerr)?;
        Ok(rc.unbind())
    }
}
