vika 0.1.2

A Rust API for Vika.
Documentation
use std::collections::HashMap;

use serde::{Deserialize, Serialize};

use crate::{
    common::config::Config, field::FieldsManager, record::RecordsManager, view::ViewsManager,
};

#[derive(Debug, Default, Serialize, Deserialize)]
pub struct Data {
    #[serde(rename = "pageNum")]
    pub page_num: usize,
    #[serde(rename = "pageSize")]
    pub page_size: usize,
    ///The total number of records that meet the filter criteria.
    pub records: Vec<Record>,

    ///The actual number of records returned per page.If 'pageSize=100' is specified when requesting, but the actual number of records is only 35, 35 is returned.
    pub total: usize,
}

#[derive(Debug, Default, Serialize, Deserialize)]
pub struct Record {
    ///record ID
    #[serde(rename = "recordId")]
    pub record_id: String,
    ///The creation time of the record, in timestamp format
    #[serde(rename = "createdAt")]
    pub created_at: usize,
    ///The modification time of the record, in timestamp format
    #[serde(rename = "updatedAt")]
    pub updated_at: usize,
    ///The data of the corresponding field in a record, the return format is {'fieldName': 'fielValue'}, please refer to Record for details
    pub fields: FieldContext,
}
#[derive(Debug, Default, Serialize, Deserialize)]
pub struct FieldContext {
    #[serde(flatten)]
    pub fields: HashMap<String, serde_json::Value>,
}

pub struct DatasheetManager {
    pub space_id: String,
    pub datasheet_id: String,
    pub views: ViewsManager,
    pub fields: FieldsManager,
    pub records: RecordsManager,
    pub config: Config,
}

pub struct DatasheetsManager {
    pub space_id: String,
    pub config: Config,
}

impl DatasheetsManager {
    // pub async fn query_all_datasheets(&self) -> anyhow::Result<
    pub fn datasheet(&self, datasheet_id: &str) -> DatasheetManager {
        DatasheetManager {
            space_id: self.space_id.clone(),
            datasheet_id: datasheet_id.into(),
            views: ViewsManager {
                datasheet_id: datasheet_id.into(),
                config: self.config.clone(),
            },
            fields: FieldsManager {
                space_id: self.space_id.clone(),
                datasheet_id: datasheet_id.into(),
                view_id: None,
                config: self.config.clone(),
            },
            records: RecordsManager {
                space_id: self.space_id.clone(),
                datasheet_id: datasheet_id.into(),
                view_id: None,
                config: self.config.clone(),
            },
            config: self.config.clone(),
        }
    }

    pub fn with_view(&self, datasheet_id: &str, view_id: &str) -> DatasheetManager {
        DatasheetManager {
            space_id: self.space_id.clone(),
            datasheet_id: datasheet_id.into(),
            views: ViewsManager {
                datasheet_id: datasheet_id.into(),
                config: self.config.clone(),
            },
            fields: FieldsManager {
                space_id: self.space_id.clone(),
                datasheet_id: datasheet_id.into(),
                view_id: Some(view_id.into()),
                config: self.config.clone(),
            },
            records: RecordsManager {
                space_id: self.space_id.clone(),
                datasheet_id: datasheet_id.into(),
                view_id: Some(view_id.into()),
                config: self.config.clone(),
            },
            config: self.config.clone(),
        }
    }
}