package execution_verification

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

type ExecutionVerificationMongoAccessor struct {
	utils.AbstractAccessor[*ExecutionVerification]
	shallow bool
}

func NewAccessor(request *tools.APIRequest) *ExecutionVerificationMongoAccessor {
	return &ExecutionVerificationMongoAccessor{
		shallow: false,
		AbstractAccessor: utils.AbstractAccessor[*ExecutionVerification]{
			Logger:         logs.CreateLogger(tools.WORKFLOW_EXECUTION.String()), // Create a logger with the data type
			Request:        request,
			Type:           tools.WORKFLOW_EXECUTION,
			New:            func() *ExecutionVerification { return &ExecutionVerification{} },
			NotImplemented: []string{"DeleteOne", "StoreOne", "CopyOne"},
		},
	}
}

func (wfa *ExecutionVerificationMongoAccessor) StoreOne(set utils.DBObject) (utils.DBObject, int, error) {
	set.(*ExecutionVerification).IsVerified = false
	return utils.GenericStoreOne(set, wfa)
}

func (wfa *ExecutionVerificationMongoAccessor) UpdateOne(set map[string]interface{}, id string) (utils.DBObject, int, error) {
	set = map[string]interface{}{
		"is_verified": true,
		"validate":    set["validate"],
	}
	return utils.GenericUpdateOne(set, id, wfa)
}
