//! Auto-generated PID  types.
//! Empfangs-bestätigung
//! Do not edit manually.
#![allow(unused_imports, non_camel_case_types)]

use serde::{Deserialize, Serialize};
use crate::segment::OwnedSegment;
use crate::cursor::{SegmentCursor, SegmentNotFound, peek_is, consume, expect_segment};

/// PID : Empfangs-bestätigung
/// Kommunikation: 
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Pid {
    pub unh: OwnedSegment,
    pub uci: OwnedSegment,
    pub unt: OwnedSegment,
}

impl Pid {
    /// Assemble this PID from a pre-tokenized segment list.
    pub fn from_segments(
        segments: &[OwnedSegment],
    ) -> Result<Self, SegmentNotFound> {
        let mut cursor = SegmentCursor::new(segments.len());

        let unh = expect_segment(segments, &mut cursor, "UNH")?.clone();
        let uci = expect_segment(segments, &mut cursor, "UCI")?.clone();
        let unt = expect_segment(segments, &mut cursor, "UNT")?.clone();

        Ok(Pid {
            unh,
            uci,
            unt,
        })
    }
}
