couchbase-core 1.0.1

Couchbase SDK core networking and protocol implementation, not intended for direct use
Documentation
/*
 *
 *  * Copyright (c) 2025 Couchbase, Inc.
 *  *
 *  * Licensed under the Apache License, Version 2.0 (the "License");
 *  * you may not use this file except in compliance with the License.
 *  * You may obtain a copy of the License at
 *  *
 *  *    http://www.apache.org/licenses/LICENSE-2.0
 *  *
 *  * Unless required by applicable law or agreed to in writing, software
 *  * distributed under the License is distributed on an "AS IS" BASIS,
 *  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  * See the License for the specific language governing permissions and
 *  * limitations under the License.
 *
 */

use crate::searchx::index;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use std::collections::HashMap;

#[derive(Serialize, Deserialize)]
pub(crate) struct SearchIndexResponseJson {
    pub status: String,
    #[serde(rename = "indexDef")]
    pub index_def: IndexJson,
}

#[derive(Serialize, Deserialize)]
pub(crate) struct SearchIndexDefsJson {
    #[serde(rename = "implVersion")]
    pub impl_version: String,
    #[serde(rename = "indexDefs")]
    pub index_defs: HashMap<String, IndexJson>,
}

#[derive(Serialize, Deserialize)]
pub(crate) struct SearchIndexesResponseJson {
    pub status: String,
    #[serde(rename = "indexDefs")]
    pub indexes: SearchIndexDefsJson,
}

#[derive(Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub(crate) struct IndexJson {
    pub name: String,
    #[serde(rename = "type")]
    pub index_type: String,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub params: Option<HashMap<String, Value>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub plan_params: Option<HashMap<String, Value>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub prev_index_uuid: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub source_name: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub source_params: Option<HashMap<String, Value>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub source_type: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none", rename = "sourceUUID")]
    pub source_uuid: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub uuid: Option<String>,
}

impl From<IndexJson> for index::Index {
    fn from(value: IndexJson) -> index::Index {
        index::Index {
            name: value.name,
            index_type: value.index_type,

            params: value.params,
            plan_params: value.plan_params,
            prev_index_uuid: value.prev_index_uuid,
            source_name: value.source_name,
            source_params: value.source_params,
            source_type: value.source_type,
            source_uuid: value.source_uuid,
            uuid: value.uuid,
        }
    }
}

impl From<index::Index> for IndexJson {
    fn from(value: index::Index) -> IndexJson {
        IndexJson {
            name: value.name,
            index_type: value.index_type,

            params: value.params,
            plan_params: value.plan_params,
            prev_index_uuid: value.prev_index_uuid,
            source_name: value.source_name,
            source_params: value.source_params,
            source_type: value.source_type,
            source_uuid: value.source_uuid,
            uuid: value.uuid,
        }
    }
}