ocpi 0.3.5

Unofficial, in progress, OCPI implementation
Documentation
use super::{CiString, DateTime, Token};

/// 13.3.4. ReserveNow Object
///
/// The evse_uid is optional. If no EVSE is specified, the Charge Point should keep
/// one EVSE available for the EV Driver identified by the given Token.
/// (This might not be supported by all Charge Points).
/// A reservation can be replaced/updated by sending a `RESERVE_NOW` request with the
/// same Location (Charge Point) and the same reservation_id.
///
/// A successful reservation will result in a new Session object being created by the CPO.
///
/// A not used Reservation of a Charge Point/EVSE MAY result in cost being made, thus also a CDR.
///
/// The eMSP provides a Token that has to be used by the Charge Point.
/// The Token provided by the eMSP for the ReserveNow SHALL be authorized by the eMSP before
/// sending it to the CPO.
/// Therefor the CPO SHALL NOT check the validity of the Token provided before sending the request to
/// the Charge Point.
///
/// If this is an OCPP Charge Point, the Charge Point decides if it needs to validate the
/// given Token, in such case:
///
/// • If this Token is of type: AD_HOC_USER or APP_USER
///   the CPO SHALL NOT do a realtime authorization at the eMSP for this .
///
/// • If this Token is of type: RFID,
///   the CPO SHALL NOT do a realtime authorization at the eMSP for this Token at the given
///   EVSE/Charge Point within 15 minutes after having received this ReserveNow.
///
/// The eMSP MAY use Tokens that have not been pushed via the Token module,
/// especially AD_HOC_USER or APP_USER Tokens are only used by commands send by an eMSP.
/// As these are never used locally at the Charge Point like RFID.
///
/// Unknown Tokens received by the CPO in the ReserveNow Object don’t need to be stored
/// in the Token module. In other words, when a Token has been received via ReserveNow,
/// the same Token does not have to be returned in a Token GET request from the eMSP.
///
/// An eMSP sending a ReserveNow SHALL only use Token that are owned by this eMSP in ReserveNow,
/// using Tokens of other eMSPs is not allowed.
///
/// The reservation_id send by the Sender (eMSP) to the Receiver (CPO) SHALL NOT be send
/// directly to a Charge Point. The CPO SHALL make sure the Reservation ID send to the
/// Charge Point is unique, is not used by another Sender (eMSP).
/// We don’t want a Sender (eMSP) to replace or cancel a reservation of another Sender (eMSP).
#[derive(Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct ReserveNow {
    /// URL that the CommandResult POST should be send to. This URL might
    /// contain an unique ID to be able to distinguish between ReserveNow
    /// requests.
    pub response_url: url::Url,

    /// Token object for how to reserve this Charge Point (and specific EVSE).
    pub token: Token,

    /// The Date/Time when this reservation ends, in UTC.
    pub expiry_date: DateTime,

    /// Reservation id, unique for this reservation. If the Receiver (typically CPO)
    /// Point already has a reservation that matches this reservationId for
    /// that Location it will replace the reservation.
    pub reservation_id: CiString<36>,

    /// Location.id of the Location (belonging to the CPO this request is send to)
    /// for which to reserve an EVSE.
    pub location_id: CiString<36>,

    /// Optional EVSE.uid of the EVSE of this Location if a specific EVSE has to be reserved.
    pub evse_id: Option<CiString<36>>,

    /// Reference to the authorization given by the eMSP, when given,
    /// this reference will be provided in the relevant Session and/or CDR.
    pub authorization_reference: Option<CiString<36>>,
}