package ocss import ( "bytes" "encoding/json" "time" ) type CarpoolBookingStatus int64 const ( CarpoolBookingWaitingConfirmation CarpoolBookingStatus = iota CarpoolBookingConfirmed CarpoolBookingCancelled CarpoolBookingCompletedPendingValidation CarpoolBookingValidated ) var carpoolBookingStatustoID = map[string]CarpoolBookingStatus{ "WAITING_CONFIRMATION": CarpoolBookingWaitingConfirmation, "CONFIRMED": CarpoolBookingConfirmed, "CANCELLED": CarpoolBookingCancelled, "COMPLETED_PENDING_VALIDATION": CarpoolBookingCompletedPendingValidation, "VALIDATED": CarpoolBookingValidated, } var carpoolBookingStatustoString = map[CarpoolBookingStatus]string{ CarpoolBookingWaitingConfirmation: "WAITING_CONFIRMATION", CarpoolBookingConfirmed: "CONFIRMED", CarpoolBookingCancelled: "CANCELLED", CarpoolBookingCompletedPendingValidation: "COMPLETED_PENDING_VALIDATION", CarpoolBookingValidated: "VALIDATED", } func (s CarpoolBookingStatus) MarshalJSON() ([]byte, error) { buffer := bytes.NewBufferString(`"`) buffer.WriteString(carpoolBookingStatustoString[s]) buffer.WriteString(`"`) return buffer.Bytes(), nil } func (bs *CarpoolBookingStatus) UnmarshalJSON(b []byte) error { var j string err := json.Unmarshal(b, &j) if err != nil { return err } // Note that if the string cannot be found then it will be set to the zero value, 'Created' in this case. *bs = carpoolBookingStatustoID[j] return nil } type CarpoolBookingEventData struct { CarpoolBooking DriverCarpoolBooking PassengerCarpoolBooking } type CarpoolBookingEvent struct { ID string `json:"id"` // TODO validate UUID IDToken string `json:"idToken"` Data CarpoolBookingEventData `json:"data"` } type CarpoolBooking struct { ID string `json:"id"` PassengerPickupDate time.Time `json:"passengerPickupDate"` PassengerPickupLat float64 `json:"passengerPickupLat"` PassengerPickupLng float64 `json:"passengerPickupLng"` PassengerDropLat float64 `json:"passengerDropLat"` PassengerDropLng float64 `json:"passengerDropLng"` PassengerPickupAddress *string `json:"passengerPickupAddress,omitempty"` PassengerDropAddress *string `json:"passengerDropAddress,omitempty"` Status CarpoolBookingStatus `json:"status"` Distance *int64 `json:"distance,omitempty"` Duration *time.Duration `json:"duration,omitempty"` WebUrl string `json:"webUrl"` } type PassengerCarpoolBooking struct { Passenger User `json:"passenger"` } type DriverCarpoolBooking struct { Driver User `json:"driver"` Price Price `json:"price"` Car *Car `json:"car,omitempty"` }