package ocss import ( "bytes" "encoding/json" "time" "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/bson/bsontype" ) 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 (s CarpoolBookingStatus) MarshalBSONValue() (bsontype.Type, []byte, error) { return bson.MarshalValue(carpoolBookingStatustoString[s]) } 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 } func (bs *CarpoolBookingStatus) UnmarshalBSON(t bsontype.Type, b []byte) error { var j string err := bson.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"` IDToken string `json:"idToken"` Data CarpoolBookingEventData `json:"data"` } type CarpoolBooking struct { ID string `json:"id" bson:"_id"` PassengerPickupDate time.Time `json:"passengerPickupDate" bson:"passengerPickupDate"` PassengerPickupLat float64 `json:"passengerPickupLat" bson:"passengerPickupLat"` PassengerPickupLng float64 `json:"passengerPickupLng" bson:"passengerPickupLng"` PassengerDropLat float64 `json:"passengerDropLat" bson:"passengerDropLat"` PassengerDropLng float64 `json:"passengerDropLng" bson:"passengerDropLng"` PassengerPickupAddress *string `json:"passengerPickupAddress,omitempty" bson:"passengerPickupAddress,omitempty"` PassengerDropAddress *string `json:"passengerDropAddress,omitempty" bson:"passengerDropAddress,omitempty"` Status CarpoolBookingStatus `json:"status"` Distance *int64 `json:"distance,omitempty" bson:"distance,omitempty"` Duration *time.Duration `json:"duration,omitempty" bson:"duration,omitempty"` WebUrl string `json:"webUrl" bson:"webUrl"` } type PassengerCarpoolBooking struct { Passenger User `json:"passenger"` } type DriverCarpoolBooking struct { Driver User `json:"driver"` Price Price `json:"price"` Car *Car `json:"car,omitempty" bson:"car,omitempty"` }