diff --git a/models/resources/interfaces.go b/models/resources/interfaces.go index a8afcdc..d4d7975 100755 --- a/models/resources/interfaces.go +++ b/models/resources/interfaces.go @@ -25,6 +25,7 @@ type ResourceInstanceITF interface { GetPricingsProfiles(peerID string, groups []string) []pricing.PricingProfileITF GetPeerGroups() ([]ResourcePartnerITF, []map[string][]string) ClearPeerGroups() + GetSelectedPartnership() ResourcePartnerITF GetPartnerships(peerID string, groups []string) []ResourcePartnerITF } diff --git a/models/resources/resource.go b/models/resources/resource.go index 090d9fe..780544c 100755 --- a/models/resources/resource.go +++ b/models/resources/resource.go @@ -144,13 +144,24 @@ type Credentials struct { type ResourceInstance[T ResourcePartnerITF] struct { utils.AbstractObject - Location GeoPoint `json:"location,omitempty" bson:"location,omitempty"` - Country countries.CountryCode `json:"country,omitempty" bson:"country,omitempty"` - AccessProtocol string `json:"access_protocol,omitempty" bson:"access_protocol,omitempty"` - Env []models.Param `json:"env,omitempty" bson:"env,omitempty"` - Inputs []models.Param `json:"inputs,omitempty" bson:"inputs,omitempty"` - Outputs []models.Param `json:"outputs,omitempty" bson:"outputs,omitempty"` - Partnerships []T `json:"partnerships,omitempty" bson:"partnerships,omitempty"` + Location GeoPoint `json:"location,omitempty" bson:"location,omitempty"` + Country countries.CountryCode `json:"country,omitempty" bson:"country,omitempty"` + AccessProtocol string `json:"access_protocol,omitempty" bson:"access_protocol,omitempty"` + Env []models.Param `json:"env,omitempty" bson:"env,omitempty"` + Inputs []models.Param `json:"inputs,omitempty" bson:"inputs,omitempty"` + Outputs []models.Param `json:"outputs,omitempty" bson:"outputs,omitempty"` + SelectedPartnershipIndex *int `json:"selected_partnership_index,omitempty" bson:"selected_partnership_index,omitempty"` // SelectedInstance is the selected instance + Partnerships []T `json:"partnerships,omitempty" bson:"partnerships,omitempty"` +} + +func (r *ResourceInstance[T]) GetSelectedPartnership() ResourcePartnerITF { + if r.SelectedPartnershipIndex != nil && len(r.Partnerships) > *r.SelectedPartnershipIndex { + return r.Partnerships[*r.SelectedPartnershipIndex] + } + if len(r.Partnerships) > 0 { + return r.Partnerships[0] + } + return nil } func (ri *ResourceInstance[T]) ClearEnv() { @@ -206,9 +217,6 @@ type ResourcePartnerShip[T pricing.PricingProfileITF] struct { func (ri *ResourcePartnerShip[T]) GetPricingsProfiles(peerID string, groups []string) []pricing.PricingProfileITF { profiles := []pricing.PricingProfileITF{} if ri.PeerGroups[peerID] != nil { - for _, ri := range ri.PricingProfiles { - profiles = append(profiles, ri) - } if slices.Contains(groups, "*") { for _, ri := range ri.PricingProfiles { profiles = append(profiles, ri)