//! The key value operations that can be performed on the key value store.
use serde::{Deserialize, Serialize};

/// Check if a key exists.
///
/// # Fields
/// * `key` - The key to check if it exists.
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
pub struct MessageExists {
	pub key: Vec<u8>,
}

/// Get the value of a key.
///
/// # Fields
/// * `key` - The key to get the value of.
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
pub struct MessageGet {
	pub key: Vec<u8>,
}

/// Set the value of a key.
///
/// # Fields
/// * `key` - The key to set the value of.
/// * `value` - The value to set the key to.
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
pub struct MessageSet {
	pub key: Vec<u8>,
	pub value: Vec<u8>,
}

/// Put a key value pair.
///
/// # Fields
/// * `key` - The key to put.
/// * `value` - The value to put.
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
pub struct MessagePut {
	pub key: Vec<u8>,
	pub value: Vec<u8>,
}

/// Put a key value pair if the value of that key is the same as the one provided.
///
/// # Fields
/// * `key` - The key to put.
/// * `value` - The value to put.
/// * `expected_value` - The expected value of the key before the PUT.
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
pub struct MessagePutc {
	pub key: Vec<u8>,
	pub value: Vec<u8>,
	pub expected_value: Option<Vec<u8>>,
}

/// Delete a key.
///
/// # Fields
/// * `key` - The key to delete.
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
pub struct MessageDel {
	pub key: Vec<u8>,
}

/// Delete a key if the value of that key is the same as the one provided.
///
/// # Fields
/// * `key` - The key to delete.
/// * `expected_value` - The expected value of the key before the DELETE.
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
pub struct MessageDelc {
	pub key: Vec<u8>,
	pub expected_value: Option<Vec<u8>>,
}

/// Delete a key and return the value.
///
/// # Fields
/// * `keys` - The keys to delete.
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
pub struct MessageDelr {
	pub begin: Vec<u8>,
	pub finish: Vec<u8>,
}

/// Get all keys within a range with a limit.
///
/// # Fields
/// * `begin` - The beginning of the range.
/// * `finish` - The end of the range.
/// * `limit` - The limit of the number of keys to return.
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
pub struct MessageKeys {
	pub begin: Vec<u8>,
	pub finish: Vec<u8>,
	pub limit: u32,
}

/// Get all keys and values within a range with a limit.
///
/// # Fields
/// * `begin` - The beginning of the range.
/// * `finish` - The end of the range.
/// * `limit` - The limit of the number of keys to return.
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
pub struct MessageScan {
	pub begin: Vec<u8>,
	pub finish: Vec<u8>,
	pub limit: u32,
}

/// The response to the `Get` operation.
///
/// # Fields
/// * `value` - The value of the key.
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
pub struct ResponseGet {
	pub value: Option<Vec<u8>>,
}

/// The response to the `Keys` operation.
///
/// # Fields
/// * `keys` - The keys within the range.
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
pub struct ResponseKeys {
	pub keys: Vec<Vec<u8>>,
}

/// The response to the `Scan` operation.
///
/// # Fields
/// * `values` - The key value pairs within the range.
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
pub struct ResponseScan {
	pub values: Vec<(Vec<u8>, Vec<u8>)>,
}
