package utils

import "penahub.gitlab.yandexcloud.net/pena-services/customer/internal/models"

func CalculateCartPurchasesAmount(tariffs []models.Tariff) uint64 {
	sum := uint64(0)

	for _, tariff := range tariffs {
		if tariff.Price == 0 {
			privilegesSum := uint64(0)

			for _, privilege := range tariff.Privileges {
				privilegesSum += privilege.Price*privilege.Amount
			}

			sum += privilegesSum

			continue
		}

		sum += tariff.Price
	}

	return sum
}

func TranslateTariffsArrayToMapPair(tariffs []models.Tariff) map[string]string {
	pair := make(map[string]string, len(tariffs))

	for _, tariff := range tariffs {
		pair[tariff.Name] = tariff.ID
	}

	return pair
}
