set up
This commit is contained in:
@@ -52,13 +52,12 @@ type AbstractInstanciatedResource[T ResourceInstanceITF] struct {
|
||||
Instances []T `json:"instances,omitempty" bson:"instances,omitempty"` // Bill is the bill of the resource // Bill is the bill of the resource
|
||||
}
|
||||
|
||||
func (abs *AbstractInstanciatedResource[T]) ConvertToPricedResource(
|
||||
t tools.DataType, request *tools.APIRequest) pricing.PricedItemITF {
|
||||
func (abs *AbstractInstanciatedResource[T]) ConvertToPricedResource(t tools.DataType, request *tools.APIRequest, buyingStrategy int, pricingStrategy int) pricing.PricedItemITF {
|
||||
instances := map[string]string{}
|
||||
profiles := []pricing.PricingProfileITF{}
|
||||
for _, instance := range abs.Instances {
|
||||
instances[instance.GetID()] = instance.GetName()
|
||||
profiles = instance.GetPricingsProfiles(request.PeerID, request.Groups)
|
||||
profiles = instance.GetPricingsProfiles(request.PeerID, request.Groups, buyingStrategy, pricingStrategy)
|
||||
}
|
||||
return &PricedResource{
|
||||
Name: abs.Name,
|
||||
@@ -184,10 +183,10 @@ func (ri *ResourceInstance[T]) GetPartnerships(peerID string, groups []string) [
|
||||
return partners
|
||||
}
|
||||
|
||||
func (ri *ResourceInstance[T]) GetPricingsProfiles(peerID string, groups []string) []pricing.PricingProfileITF {
|
||||
func (ri *ResourceInstance[T]) GetPricingsProfiles(peerID string, groups []string, buyingStrategy int, pricingStrategy int) []pricing.PricingProfileITF {
|
||||
pricings := []pricing.PricingProfileITF{}
|
||||
for _, p := range ri.Partnerships {
|
||||
pricings = append(pricings, p.GetPricingsProfiles(peerID, groups)...)
|
||||
pricings = append(pricings, p.GetPricingsProfiles(peerID, groups, buyingStrategy, pricingStrategy)...)
|
||||
}
|
||||
return pricings
|
||||
}
|
||||
@@ -211,26 +210,31 @@ func (ri *ResourceInstance[T]) ClearPeerGroups() {
|
||||
type ResourcePartnerShip[T pricing.PricingProfileITF] struct {
|
||||
Namespace string `json:"namespace" bson:"namespace" default:"default-namespace"`
|
||||
PeerGroups map[string][]string `json:"peer_groups,omitempty" bson:"peer_groups,omitempty"`
|
||||
PricingProfiles []T `json:"pricing_profiles,omitempty" bson:"pricing_profiles,omitempty"`
|
||||
PricingProfiles map[int]map[int]T `json:"pricing_profiles,omitempty" bson:"pricing_profiles,omitempty"`
|
||||
// to upgrade pricing profiles. to be a map BuyingStrategy, map of Strategy
|
||||
}
|
||||
|
||||
func (ri *ResourcePartnerShip[T]) GetPricingsProfiles(peerID string, groups []string) []pricing.PricingProfileITF {
|
||||
/*
|
||||
Le pricing doit être selectionné lors d'un scheduling...
|
||||
le type de paiement défini le type de stratégie de paiement
|
||||
note : il faut rajouté - une notion de facturation
|
||||
Une order est l'ensemble de la commande... un booking une réservation, une purchase un acte d'achat.
|
||||
Une bill (facture) représente alors... l'emission d'une facture à un instant T en but d'être honorée, envoyée ... etc.
|
||||
*/
|
||||
func (ri *ResourcePartnerShip[T]) GetPricingsProfiles(peerID string, groups []string, buyingStrategy int, pricingStrategy int) []pricing.PricingProfileITF {
|
||||
profiles := []pricing.PricingProfileITF{}
|
||||
if ri.PeerGroups[peerID] != nil {
|
||||
if slices.Contains(groups, "*") {
|
||||
for _, ri := range ri.PricingProfiles {
|
||||
profiles = append(profiles, ri)
|
||||
if ri.PeerGroups[peerID] == nil {
|
||||
return profiles
|
||||
}
|
||||
for _, p := range ri.PeerGroups[peerID] {
|
||||
if slices.Contains(groups, p) || slices.Contains(groups, "*") {
|
||||
for buyingS, ri := range ri.PricingProfiles {
|
||||
if _, ok := ri[pricingStrategy]; ok && buyingS == buyingStrategy {
|
||||
profiles = append(profiles, ri[pricingStrategy])
|
||||
}
|
||||
}
|
||||
return profiles
|
||||
}
|
||||
for _, p := range ri.PeerGroups[peerID] {
|
||||
if slices.Contains(groups, p) {
|
||||
for _, ri := range ri.PricingProfiles {
|
||||
profiles = append(profiles, ri)
|
||||
}
|
||||
return profiles
|
||||
}
|
||||
}
|
||||
}
|
||||
return profiles
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user