package entitymapping

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

// providerMapping has method to map provider entities to view models
type planMapping struct {
	mapper *Mapper
}

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

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

	return retVal
}

func (mapping *planMapping) ToPlanEntity(model viewmodel.Plan) entity.Plan {
	return entity.Plan{
		UUID:         model.ID,
		Name:         model.Name,
		InternalID:   model.InternalID,
		Status:       model.Status,
		PlanEntityID: model.PlanEntityID,
		EntityID:     model.EntityID,
		PayerID:      model.PayerID,
		PayerName:    model.PayerName,
		PrefixUUID:   model.PrefixID,
		AlphaPrefix:  model.AlphaPrefix,
		Active:       model.Active,
	}
}

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

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

	return retVal
}

func (mapping *planMapping) ToPlanModel(model entity.Plan) viewmodel.Plan {
	return viewmodel.Plan{
		ID:           model.UUID,
		Name:         model.Name,
		InternalID:   model.InternalID,
		Status:       model.Status,
		PlanEntityID: model.PlanEntityID,
		EntityID:     model.EntityID,
		PayerID:      model.PayerID,
		PayerName:    model.PayerName,
		PrefixID:     model.PrefixUUID,
		AlphaPrefix:  model.AlphaPrefix,
		Active:       model.Active,
	}
}
