|
1 | 1 | package types |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "github.com/lorenzodonini/ocpp-go/ocpp2.0.1/types" |
4 | 5 | "gopkg.in/go-playground/validator.v9" |
5 | 6 | ) |
6 | 7 |
|
@@ -74,3 +75,87 @@ func NewSalesTariff(id int, salesTariffEntries []SalesTariffEntry) *SalesTariff |
74 | 75 | SalesTariffEntry: salesTariffEntries, |
75 | 76 | } |
76 | 77 | } |
| 78 | + |
| 79 | +type TariffCost string |
| 80 | + |
| 81 | +const ( |
| 82 | + TariffCostNormal = "NormalCost" |
| 83 | + TariffCostMinimum = "MinCost" |
| 84 | + TariffCostMaximum = "MaxCost" |
| 85 | +) |
| 86 | + |
| 87 | +func isValidTariffCost(fl validator.FieldLevel) bool { |
| 88 | + costType := TariffCost(fl.Field().String()) |
| 89 | + switch costType { |
| 90 | + case TariffCostNormal, TariffCostMinimum, TariffCostMaximum: |
| 91 | + return true |
| 92 | + default: |
| 93 | + return false |
| 94 | + } |
| 95 | +} |
| 96 | + |
| 97 | +type CostDimensionType string |
| 98 | + |
| 99 | +const ( |
| 100 | + CostDimensionTypeEnergy CostDimensionType = "Energy" // Cost dimension for energy consumed. |
| 101 | + CostDimensionTypeChargingTime CostDimensionType = "ChargingTime" // Cost dimension for the time the EV was charging. |
| 102 | + CostDimensionTypeIdleTime CostDimensionType = "IdleTime" // Cost dimension for the time the EV was idle. |
| 103 | + CostDimensionMinCurrent CostDimensionType = "MinCurrent" // Cost dimension for the minimum current used during the charging session. |
| 104 | + CostDimensionMaxCurrent CostDimensionType = "MaxCurrent" // Cost dimension for the maximum current used during the charging session. |
| 105 | + CostDimensionMinPower CostDimensionType = "MinPower" // Cost dimension for the minimum power used during the charging session. |
| 106 | + CostDimensionMaxPower CostDimensionType = "MaxPower" // Cost dimension for the maximum power used during the charging session. |
| 107 | +) |
| 108 | + |
| 109 | +func isValidCostDimensionType(fl validator.FieldLevel) bool { |
| 110 | + dimensionType := CostDimensionType(fl.Field().String()) |
| 111 | + switch dimensionType { |
| 112 | + case CostDimensionTypeEnergy, CostDimensionTypeChargingTime, CostDimensionTypeIdleTime, |
| 113 | + CostDimensionMinCurrent, CostDimensionMaxCurrent, CostDimensionMinPower, CostDimensionMaxPower: |
| 114 | + return true |
| 115 | + default: |
| 116 | + return false |
| 117 | + } |
| 118 | +} |
| 119 | + |
| 120 | +type CostDetails struct { |
| 121 | + FailureToCalculate *bool `json:"failureToCalculate,omitempty"` |
| 122 | + FailureReason *string `json:"failureReason,omitempty" validate:"omitempty,max=500"` |
| 123 | + ChargingPeriods []ChargingPeriod `json:"chargingPeriods,omitempty" validate:"omitempty,dive"` |
| 124 | + TotalCost TotalCost `json:"totalCost" validate:"required,dive"` |
| 125 | + TotalUsage TotalUsage `json:"totalUsage" validate:"required,dive"` // Total usage of the EV during the charging session. |
| 126 | +} |
| 127 | + |
| 128 | +type TotalCost struct { |
| 129 | + Currency string `json:"currency" validate:"required,max=3"` // The currency of the total cost. |
| 130 | + TypeOfCost TariffCost `json:"typeOfCost" validate:"required,tariffCost21"` // The type of cost, e.g. NormalCost, MinCost, MaxCost. |
| 131 | + Fixed *Price `json:"fixedPrice,omitempty" validate:"omitempty,dive"` |
| 132 | + Energy *Price `json:"energy,omitempty" validate:"omitempty,dive"` |
| 133 | + ChargingTime *Price `json:"chargingTime,omitempty" validate:"omitempty,dive"` |
| 134 | + IdleTime *Price `json:"idleTime,omitempty" validate:"omitempty,dive"` |
| 135 | + ReservationTime *Price `json:"reservationTime,omitempty" validate:"omitempty,dive"` |
| 136 | + Total TotalPrice `json:"total" validate:"required,dive"` // Total cost of the charging session. |
| 137 | + ReservationFixed *Price `json:"reservationFixed,omitempty" validate:"omitempty,dive"` |
| 138 | +} |
| 139 | + |
| 140 | +type TotalPrice struct { |
| 141 | + ExclTax *float64 `json:"exclTax,omitempty" validate:"omitempty"` // Total price excluding tax. |
| 142 | + InclTax *float64 `json:"inclTax,omitempty" validate:"omitempty"` // Total price including tax. |
| 143 | +} |
| 144 | + |
| 145 | +type TotalUsage struct { |
| 146 | + Energy float64 `json:"energy" validate:"required"` |
| 147 | + ChargingTime int `json:"chargingTime" validate:"required"` |
| 148 | + IdleTime int `json:"idleTime" validate:"required"` // Total idle time of the EV during the charging session, in seconds. |
| 149 | + ReservationTime *int `json:"reservationTime,omitempty" validate:"omitempty"` // Total reservation time of the EV during the charging session, in seconds. |
| 150 | +} |
| 151 | + |
| 152 | +type ChargingPeriod struct { |
| 153 | + TariffId *string `json:"tariffId,omitempty" validate:"omitempty,max=60"` // The ID of the tariff used for this charging period. |
| 154 | + StartPeriod types.DateTime `json:"startPeriod" validate:"required"` // The start of the charging period. |
| 155 | + Dimensions []CostDimension `json:"dimensions,omitempty" validate:"omitempty,dive"` |
| 156 | +} |
| 157 | + |
| 158 | +type CostDimension struct { |
| 159 | + Type CostDimensionType `json:"type" validate:"required,costDimension21"` |
| 160 | + Volume float64 `json:"volume" validate:"required"` |
| 161 | +} |
0 commit comments