package entitymapping

import (
	"strings"

	"sync"
)

var (
	instance *Mapper
	once     sync.Once
)

// Mapper has mapping methods to map entities to view models
type Mapper struct {
	User          *userMapping
	Ride          *rideMapping
	Visit         *visitMapping
	Address       *addressMapping
	Provider      *providerMapping
	Notification  *notificationMapping
	Profile       *profileMapping
	Organization  *organizationMapping
	Zipcode       *zipcodeMapping
	Plan          *planMapping
	PasswordReset *passwordResetMapping
}

// New returns an EntityMapper for fluent mapping
func New() *Mapper {
	once.Do(func() {
		instance = &Mapper{}

		instance.User = &userMapping{instance}
		instance.Ride = &rideMapping{instance}
		instance.Visit = &visitMapping{instance}
		instance.Address = &addressMapping{instance}
		instance.Provider = &providerMapping{instance}
		instance.Notification = &notificationMapping{instance}
		instance.Profile = &profileMapping{instance}
		instance.Organization = &organizationMapping{instance}
		instance.Zipcode = &zipcodeMapping{instance}
		instance.Plan = &planMapping{instance}
		instance.PasswordReset = &passwordResetMapping{instance}
	})

	return instance
}

// isEmpty returns the alternative option in case the first is empty
func ifEmpty(firstOption string, alternativeOption string) string {
	if strings.TrimSpace(firstOption) == "" {
		return alternativeOption
	}

	return firstOption
}
