package entitymapping

import (
	"bitbucket.org/nemt/nemt-portal-api/application/viewmodel"
	"bitbucket.org/nemt/nemt-portal-api/domain/entity"
)

// rideMapping has method to map ride entities to view models
type addressMapping struct {
	mapper *Mapper
}

// ToVisitEntity maps a User entity to User view model
func (mapping *addressMapping) ToAddressEntity(item viewmodel.Address) entity.Address {
	return entity.Address{
		UUID:        item.UUID,
		InternalID:  item.InternalID,
		Name:        item.Name,
		Address:     item.Address,
		AddressType: mapping.ToParamEntity(item.AddressType),
		Latitude:    item.Latitude,
		Longitude:   item.Longitude,
		Origin:      mapping.ToParamEntity(item.Type),
		User:        mapping.mapper.User.ToUserEntity(item.User),
		CreatedUser: entity.User{
			UUID: item.CreatedUserUUID,
		},
	}
}

func (mapping *addressMapping) ToParamEntity(item string) entity.Params {
	return entity.Params{
		Key: item,
	}
}

// ToVisitEntity maps a User entity to User view model
func (mapping *addressMapping) ToAddressModel(item entity.Address) viewmodel.Address {
	return viewmodel.Address{
		UUID:            item.UUID,
		InternalID:      item.InternalID,
		Name:            item.Name,
		Address:         item.Address,
		AddressType:     item.AddressType.Key,
		AddressTypeName: item.AddressType.Name,
		Latitude:        item.Latitude,
		Longitude:       item.Longitude,
		Type:            item.Origin.Key,
		User:            mapping.mapper.User.ToUserModel(item.User),
		CreatedUserUUID: item.CreatedUser.UUID,
	}
}

// ToUserEntitySlice maps a User entity slice to User view model slice
func (mapping *addressMapping) ToAddressEntitySlice(list []viewmodel.Address) (retVal []entity.Address) {
	retVal = make([]entity.Address, 0)

	for _, item := range list {
		retVal = append(retVal, mapping.ToAddressEntity(item))
	}

	return retVal
}

// ToRideModelSlice maps a Ride entity slice to Ride view model slice
func (mapping *addressMapping) ToAddressModelSlice(list []entity.Address) (retVal []viewmodel.Address) {
	retVal = make([]viewmodel.Address, 0)

	for _, item := range list {
		retVal = append(retVal, mapping.ToAddressModel(item))
	}

	return retVal
}
