ocpi-tariffs 0.20.0

OCPI tariff calculations
Documentation
use std::sync::LazyLock;

use crate::{json::schema, json_schema};

/// The fields and structure allowed for a V221 tariff.
pub static TARIFF_SCHEMA: LazyLock<schema::Element> = LazyLock::new(|| {
    json_schema!({
        "country_code",
        "party_id",
        "id",
        "currency",
        "type",
        "tariff_alt_text": [{
            "language",
            "text"
        }],
        "tariff_alt_url",
        "min_price": {
            "excl_vat",
            "incl_vat"
        },
        "max_price": {
            "excl_vat",
            "incl_vat"
        },
        "elements": [{
            "price_components": [{
                "type",
                "price",
                "vat",
                "step_size"
            }],
            "restrictions": {
                "start_time",
                "end_time",
                "start_date",
                "end_date",
                "min_kwh",
                "max_kwh",
                "min_current",
                "max_current",
                "min_power",
                "max_power",
                "min_duration",
                "max_duration",
                "day_of_week": [],
                "reservation"
            }
        }],
        "start_date_time",
        "end_date_time",
        "energy_mix": {
            "is_green_energy",
            "energy_sources": [{
                "source",
                "percentage"
            }],
            "environ_impact": [{
                "category",
                "amount"
            }],
            "supplier_name",
            "energy_product_name",
        },
        "last_updated",
    })
});

/// The fields and structure allowed for a V221 CDR.
pub static CDR_SCHEMA: LazyLock<schema::Element> = LazyLock::new(|| {
    json_schema!({
        "country_code",
        "party_id",
        "id",
        "start_date_time",
        "end_date_time",
        "session_id",
        "cdr_token": {
            "country_code",
            "party_id",
            "uid",
            "type",
            "contract_id"
        },
        "auth_id",
        "auth_method",
        "authorization_reference",
        "cdr_location": {
            "id",
            "name",
            "address",
            "city",
            "postal_code",
            "state",
            "country",
            "coordinates": {
                "latitude",
                "longitude"
            },
            "evse_uid",
            "evse_id",
            "connector_id",
            "connector_standard",
            "connector_format",
            "connector_power_type"
        },
        "meter_id",
        "currency",
        "tariffs": [{
            "country_code",
            "party_id",
            "id",
            "currency",
            "type",
            "tariff_alt_text": [{
                "language",
                "text"
            }],
            "tariff_alt_url",
            "min_price": {
                "excl_vat",
                "incl_vat"
            },
            "max_price": {
                "excl_vat",
                "incl_vat"
            },
            "elements": [{
                "price_components": [{
                    "type",
                    "price",
                    "vat",
                    "step_size"
                }],
                "restrictions": {
                    "start_time",
                    "end_time",
                    "start_date",
                    "end_date",
                    "min_kwh",
                    "max_kwh",
                    "min_current",
                    "max_current",
                    "min_power",
                    "max_power",
                    "min_duration",
                    "max_duration",
                    "day_of_week": [],
                    "reservation"
                }
            }],
            "start_date_time",
            "end_date_time",
            "energy_mix": {
                "is_green_energy",
                "energy_sources": [{
                    "source",
                    "percentage"
                }],
                "environ_impact": [{
                    "category",
                    "amount"
                }],
                "supplier_name",
                "energy_product_name",
            },
            "last_updated",
        }],
        "charging_periods": [{
            "start_date_time",
            "dimensions": [{
                "type",
                "volume"
            }],
            "tariff_id"
        }],
        "signed_data": {
            "encoding_method",
            "encoding_method_version",
            "public_key",
            "signed_values": [{
                "nature",
                "plain_data",
                "signed_data"
            }],
            "url"
        },
        "total_cost": {
            "excl_vat",
            "incl_vat"
        },
        "total_fixed_cost": {
            "excl_vat",
            "incl_vat"
        },
        "total_energy",
        "total_energy_cost": {
            "excl_vat",
            "incl_vat"
        },
        "total_time",
        "total_time_cost": {
            "excl_vat",
            "incl_vat"
        },
        "total_parking_time",
        "total_parking_cost": {
            "excl_vat",
            "incl_vat"
        },
        "total_reservation_cost": {
            "excl_vat",
            "incl_vat"
        },
        "remark",
        "invoice_reference_id",
        "credit",
        "credit_reference_id",
        "home_charging_compensation",
        "last_updated",
    })
});