package ocss import ( "bytes" "encoding/json" "fmt" "time" "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/bson/bsontype" "go.mongodb.org/mongo-driver/x/bsonx/bsoncore" ) type BookingStatus int64 const ( BookingInitiated BookingStatus = iota // BookingWaitingConfirmation BookingWaitingDriverConfirmation BookingWaitingPassengerConfirmation BookingConfirmed BookingCancelled BookingCompletedPendingValidation BookingValidated ) var bookingStatustoID = map[string]BookingStatus{ "INITIATED": BookingInitiated, // "WAITING_CONFIRMATION": BookingWaitingConfirmation, "WAITING_DRIVER_CONFIRMATION": BookingWaitingDriverConfirmation, "WAITING_PASSENGER_CONFIRMATION": BookingWaitingPassengerConfirmation, "CONFIRMED": BookingConfirmed, "CANCELLED": BookingCancelled, "COMPLETED_PENDING_VALIDATION": BookingCompletedPendingValidation, "VALIDATED": BookingValidated, } var bookingStatustoString = map[BookingStatus]string{ BookingInitiated: "INITIATED", // BookingWaitingConfirmation: "WAITING_CONFIRMATION", BookingWaitingDriverConfirmation: "WAITING_DRIVER_CONFIRMATION", BookingWaitingPassengerConfirmation: "WAITING_PASSENGER_CONFIRMATION", BookingConfirmed: "CONFIRMED", BookingCancelled: "CANCELLED", BookingCompletedPendingValidation: "COMPLETED_PENDING_VALIDATION", BookingValidated: "VALIDATED", } func (s BookingStatus) MarshalJSON() ([]byte, error) { buffer := bytes.NewBufferString(`"`) buffer.WriteString(bookingStatustoString[s]) buffer.WriteString(`"`) return buffer.Bytes(), nil } func (s BookingStatus) MarshalBSONValue() (bsontype.Type, []byte, error) { return bson.MarshalValue(bookingStatustoString[s]) } func (bs *BookingStatus) UnmarshalJSON(b []byte) error { var j string err := json.Unmarshal(b, &j) if err != nil { return err } *bs = bookingStatustoID[j] return nil } func (bs *BookingStatus) UnmarshalBSONValue(t bsontype.Type, b []byte) error { if t == bsontype.Null || len(b) == 0 { return nil } j, _, ok := bsoncore.ReadString(b) if !ok { return fmt.Errorf("cannot parse status") } *bs = bookingStatustoID[j] return nil } func (bs *BookingStatus) String() string { if bs == nil { return "" } return bookingStatustoString[*bs] } func BookingStatusFromString(bs string) BookingStatus { return bookingStatustoID[bs] } type Booking struct { ID string `json:"id" bson:"_id"` Driver User `json:"driver"` Passenger User `json:"passenger"` PassengerPickupDate OCSSTime `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 BookingStatus `json:"status"` Distance *int64 `json:"distance,omitempty" bson:"distance,omitempty"` Duration *time.Duration `json:"duration,omitempty" bson:"duration,omitempty"` WebUrl *string `json:"webUrl,omitempty" bson:"webUrl,omitempty"` Price Price `json:"price"` Car *Car `json:"car,omitempty" bson:"car,omitempty"` DriverJourneyID string `json:"driverJourneyId" bson:"driverJourneyId"` PassengerJourneyID string `json:"passengerJourneyId" bson:"passengerJourneyId"` }