package execution_verification

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

/*
* ExecutionVerification is a struct that represents a list of workflow executions
* Warning: No user can write (del, post, put) a workflow execution, it is only used by the system
* workflows generate their own executions
 */
type ExecutionVerification struct {
	utils.AbstractObject        // AbstractObject contains the basic fields of an object (id, name)
	WorkflowID           string `json:"workflow_id" bson:"workflow_id,omitempty"` // WorkflowID is the ID of the workflow
	Payload              string `json:"payload" bson:"payload,omitempty"`
	IsVerified           bool   `json:"is_verified" bson:"is_verified,omitempty"`
	Validate             bool   `json:"validate" bson:"validate,omitempty"`
}

func (ri *ExecutionVerification) Extend(typ ...string) map[string][]tools.DataType {
	ext := ri.AbstractObject.Extend(typ...)
	for _, t := range typ {
		switch t {
		case "wokflow":
			if _, ok := ext[t]; !ok {
				ext[t] = []tools.DataType{}
			}
			ext[t] = append(ext[t], tools.WORKFLOW)
		}
	}
	return ext
}

func (r *ExecutionVerification) StoreDraftDefault() {
	r.IsDraft = false // TODO: TEMPORARY
}

func (d *ExecutionVerification) GetAccessor(request *tools.APIRequest) utils.Accessor {
	return NewAccessor(request) // Create a new instance of the accessor
}

func (d *ExecutionVerification) VerifyAuth(callName string, request *tools.APIRequest) bool {
	return true
}
