// @generated

/*---------------------------------------------------------------------------------------------
 *  Copyright (C) 2024-2026 Posit Software, PBC. All rights reserved.
 *--------------------------------------------------------------------------------------------*/

//
// AUTO-GENERATED from plot.json; do not edit.
//

use serde::Deserialize;
use serde::Serialize;

/// The intrinsic size of a plot, if known
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
pub struct IntrinsicSize {
	/// The width of the plot
	pub width: f64,

	/// The height of the plot
	pub height: f64,

	/// The unit of measurement of the plot's dimensions
	pub unit: PlotUnit,

	/// The source of the intrinsic size e.g. 'Matplotlib'
	pub source: String
}

/// The plot's metadata
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
pub struct PlotMetadata {
	/// A unique, human-readable name for the plot
	pub name: String,

	/// The kind of plot e.g. 'Matplotlib', 'ggplot2', etc.
	pub kind: String,

	/// The ID of the code fragment that produced the plot
	pub execution_id: String,

	/// The code fragment that produced the plot
	pub code: String,

	/// The origin of the plot, if known
	pub origin: Option<PlotOrigin>
}

/// A rendered plot
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
pub struct PlotResult {
	/// The plot data, as a base64-encoded string
	pub data: String,

	/// The MIME type of the plot data
	pub mime_type: String,

	/// The settings used to render the plot
	pub settings: Option<PlotRenderSettings>
}

/// The size of a plot
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq)]
pub struct PlotSize {
	/// The plot's height, in pixels
	pub height: i64,

	/// The plot's width, in pixels
	pub width: i64
}

/// The origin (source) of a plot
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
pub struct PlotOrigin {
	/// The URI of the document containing the code that produced the plot, if
	/// available
	pub uri: String,

	/// The range within the document at uri that produced the plot, if
	/// available
	pub range: Option<PlotRange>
}

/// The range of a plot within a document
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
pub struct PlotRange {
	/// The line number on which the plot starts (0-indexed)
	pub start_line: i64,

	/// The character number on which the plot starts (0-indexed)
	pub start_character: i64,

	/// The line number on which the plot ends (0-indexed)
	pub end_line: i64,

	/// The character number on which the plot ends (0-indexed)
	pub end_character: i64
}

/// The settings used to render the plot
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq)]
pub struct PlotRenderSettings {
	/// Plot size to render the plot to
	pub size: PlotSize,

	/// The pixel ratio of the display device
	pub pixel_ratio: f64,

	/// Format in which to render the plot
	pub format: PlotRenderFormat
}

/// Possible values for PlotUnit
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, strum_macros::Display, strum_macros::EnumString)]
pub enum PlotUnit {
	#[serde(rename = "pixels")]
	#[strum(to_string = "pixels")]
	Pixels,

	#[serde(rename = "inches")]
	#[strum(to_string = "inches")]
	Inches
}

/// Possible values for PlotRenderFormat
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, strum_macros::Display, strum_macros::EnumString)]
pub enum PlotRenderFormat {
	#[serde(rename = "png")]
	#[strum(to_string = "png")]
	Png,

	#[serde(rename = "jpeg")]
	#[strum(to_string = "jpeg")]
	Jpeg,

	#[serde(rename = "svg")]
	#[strum(to_string = "svg")]
	Svg,

	#[serde(rename = "pdf")]
	#[strum(to_string = "pdf")]
	Pdf,

	#[serde(rename = "tiff")]
	#[strum(to_string = "tiff")]
	Tiff
}

/// Parameters for the Render method.
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
pub struct RenderParams {
	/// The requested size of the plot. If not provided, the plot will be
	/// rendered at its intrinsic size.
	pub size: Option<PlotSize>,

	/// The pixel ratio of the display device
	pub pixel_ratio: f64,

	/// The requested plot format
	pub format: PlotRenderFormat,
}

/// Parameters for the Update method.
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
pub struct UpdateParams {
	/// Optional pre-rendering data for immediate display
	pub pre_render: Option<PlotResult>,
}

/// Parameters for the Show method.
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
pub struct ShowParams {
	/// Optional pre-rendering data for immediate display
	pub pre_render: Option<PlotResult>,
}

/**
 * Backend RPC request types for the plot comm
 */
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
#[serde(tag = "method", content = "params")]
pub enum PlotBackendRequest {
	/// Get the intrinsic size of a plot, if known.
	///
	/// The intrinsic size of a plot is the size at which a plot would be if
	/// no size constraints were applied by Positron.
	#[serde(rename = "get_intrinsic_size")]
	GetIntrinsicSize,

	/// Get metadata for the plot
	///
	/// Get metadata for the plot
	#[serde(rename = "get_metadata")]
	GetMetadata,

	/// Render a plot
	///
	/// Requests a plot to be rendered. The plot data is returned in a
	/// base64-encoded string.
	#[serde(rename = "render")]
	Render(RenderParams),

}

/**
 * Backend RPC Reply types for the plot comm
 */
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
#[serde(tag = "method", content = "result")]
pub enum PlotBackendReply {
	/// The intrinsic size of a plot, if known
	GetIntrinsicSizeReply(Option<IntrinsicSize>),

	/// The plot's metadata
	GetMetadataReply(PlotMetadata),

	/// A rendered plot
	RenderReply(PlotResult),

}

/**
 * Frontend RPC request types for the plot comm
 */
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
#[serde(tag = "method", content = "params")]
pub enum PlotFrontendRequest {
}

/**
 * Frontend RPC Reply types for the plot comm
 */
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
#[serde(tag = "method", content = "result")]
pub enum PlotFrontendReply {
}

/**
 * Frontend events for the plot comm
 */
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
#[serde(tag = "method", content = "params")]
pub enum PlotFrontendEvent {
	#[serde(rename = "update")]
	Update(UpdateParams),

	#[serde(rename = "show")]
	Show(ShowParams),

}

