package resources

import (
	"cloud.o-forge.io/core/oc-lib/models/common/pricing"
	"cloud.o-forge.io/core/oc-lib/models/utils"
	"cloud.o-forge.io/core/oc-lib/tools"
)

type WorkflowResourcePricingProfile struct{}

// WorkflowResource is a struct that represents a workflow resource
// it defines the resource workflow
type WorkflowResource struct {
	AbstractResource
	WorkflowID string `bson:"workflow_id,omitempty" json:"workflow_id,omitempty"` // WorkflowID is the ID of the native workflow
}

func (d *WorkflowResource) GetAccessor(request *tools.APIRequest) utils.Accessor {
	return NewAccessor[*WorkflowResource](tools.WORKFLOW_RESOURCE, request)
}

func (r *WorkflowResource) AddInstances(instance ResourceInstanceITF) {
}

func (r *WorkflowResource) GetType() string {
	return tools.WORKFLOW_RESOURCE.String()
}

func (d *WorkflowResource) ClearEnv() utils.DBObject {
	return d
}

func (w *WorkflowResource) SetAllowedInstances(request *tools.APIRequest, ids ...string) []ResourceInstanceITF {
	// WorkflowResource has no instances, but still carries AEs that must be
	// filtered before the resource is returned to a non-owner, non-admin peer.
	if !((request != nil && request.PeerID == w.CreatorID && request.PeerID != "") || request.Admin) {
		if request != nil {
			w.FilterExploitationAuthorizations(request.PeerID, request.Admin)
		}
	}
	return []ResourceInstanceITF{}
}

func (r *WorkflowResource) GetSelectedInstance(selected *int) ResourceInstanceITF {
	return nil
}

func (w *WorkflowResource) ConvertToPricedResource(t tools.DataType, selectedInstance *int, selectedPartnership *int, selectedBuyingStrategy *int, selectedStrategy *int, selectedBookingModeIndex *int, request *tools.APIRequest) (pricing.PricedItemITF, error) {
	return &PricedResource[*pricing.ExploitPricingProfile[pricing.TimePricingStrategy]]{
		Name:         w.Name,
		Logo:         w.Logo,
		ResourceID:   w.UUID,
		ResourceType: t,
		Quantity:     1,
		CreatorID:    w.CreatorID,
	}, nil // TODO ???
}

// TODO : as instanciated resource !
