use serde::{Deserialize, Serialize}; /*
                                      * Service Control API
                                      *
                                      * Provides admission control and telemetry reporting for services integrated with Service Infrastructure.
                                      *
                                      * The version of the OpenAPI document: v1
                                      *
                                      * Generated by: https://openapi-generator.tech
                                      */

use crate::google_rest_apis::servicecontrol_v1::models;

/// TraceSpan : A span represents a single operation within a trace. Spans can be nested to form a trace tree. Often, a trace contains a root span that describes the end-to-end latency, and one or more subspans for its sub-operations. A trace can also contain multiple root spans, or none at all. Spans do not need to be contiguous—there may be gaps or overlaps between spans in a trace.
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct TraceSpan {
    #[serde(rename = "attributes", skip_serializing_if = "Option::is_none")]
    pub attributes: Option<Box<models::Attributes>>,
    /// An optional number of child spans that were generated while this span was active. If set, allows implementation to detect missing child spans.
    #[serde(rename = "childSpanCount", skip_serializing_if = "Option::is_none")]
    pub child_span_count: Option<i32>,
    #[serde(rename = "displayName", skip_serializing_if = "Option::is_none")]
    pub display_name: Option<Box<models::TruncatableString>>,
    /// The end time of the span. On the client side, this is the time kept by the local machine where the span execution ends. On the server side, this is the time when the server application handler stops running.
    #[serde(rename = "endTime", skip_serializing_if = "Option::is_none")]
    pub end_time: Option<String>,
    /// The resource name of the span in the following format: projects/[PROJECT_ID]/traces/[TRACE_ID]/spans/SPAN_ID is a unique identifier for a trace within a project; it is a 32-character hexadecimal encoding of a 16-byte array. [SPAN_ID] is a unique identifier for a span within a trace; it is a 16-character hexadecimal encoding of an 8-byte array.
    #[serde(rename = "name", skip_serializing_if = "Option::is_none")]
    pub name: Option<String>,
    /// The [SPAN_ID] of this span's parent span. If this is a root span, then this field must be empty.
    #[serde(rename = "parentSpanId", skip_serializing_if = "Option::is_none")]
    pub parent_span_id: Option<String>,
    /// (Optional) Set this parameter to indicate whether this span is in the same process as its parent. If you do not set this parameter, Stackdriver Trace is unable to take advantage of this helpful information.
    #[serde(
        rename = "sameProcessAsParentSpan",
        skip_serializing_if = "Option::is_none"
    )]
    pub same_process_as_parent_span: Option<bool>,
    /// The [SPAN_ID] portion of the span's resource name.
    #[serde(rename = "spanId", skip_serializing_if = "Option::is_none")]
    pub span_id: Option<String>,
    /// Distinguishes between spans generated in a particular context. For example, two spans with the same name may be distinguished using `CLIENT` (caller) and `SERVER` (callee) to identify an RPC call.
    #[serde(rename = "spanKind", skip_serializing_if = "Option::is_none")]
    pub span_kind: Option<SpanKind>,
    /// The start time of the span. On the client side, this is the time kept by the local machine where the span execution starts. On the server side, this is the time when the server's application handler starts running.
    #[serde(rename = "startTime", skip_serializing_if = "Option::is_none")]
    pub start_time: Option<String>,
    #[serde(rename = "status", skip_serializing_if = "Option::is_none")]
    pub status: Option<Box<models::Status>>,
}

impl TraceSpan {
    /// A span represents a single operation within a trace. Spans can be nested to form a trace tree. Often, a trace contains a root span that describes the end-to-end latency, and one or more subspans for its sub-operations. A trace can also contain multiple root spans, or none at all. Spans do not need to be contiguous—there may be gaps or overlaps between spans in a trace.
    pub fn new() -> TraceSpan {
        TraceSpan {
            attributes: None,
            child_span_count: None,
            display_name: None,
            end_time: None,
            name: None,
            parent_span_id: None,
            same_process_as_parent_span: None,
            span_id: None,
            span_kind: None,
            start_time: None,
            status: None,
        }
    }
}
/// Distinguishes between spans generated in a particular context. For example, two spans with the same name may be distinguished using `CLIENT` (caller) and `SERVER` (callee) to identify an RPC call.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum SpanKind {
    #[serde(rename = "SPAN_KIND_UNSPECIFIED")]
    SpanKindUnspecified,
    #[serde(rename = "INTERNAL")]
    Internal,
    #[serde(rename = "SERVER")]
    Server,
    #[serde(rename = "CLIENT")]
    Client,
    #[serde(rename = "PRODUCER")]
    Producer,
    #[serde(rename = "CONSUMER")]
    Consumer,
}

impl Default for SpanKind {
    fn default() -> SpanKind {
        Self::SpanKindUnspecified
    }
}
