package reqbuilder

import (
	"gitlink.org.cn/cloudream/common/utils/lo2"
	"gitlink.org.cn/cloudream/jcs-pub/common/pkgs/distlock"
	"gitlink.org.cn/cloudream/jcs-pub/common/pkgs/distlock/types"
)

type LockRequestBuilder struct {
	locks []types.Lock
}

func NewBuilder() *LockRequestBuilder {
	return &LockRequestBuilder{}
}

func (b *LockRequestBuilder) IsEmpty() bool {
	return len(b.locks) == 0
}

func (b *LockRequestBuilder) Build() types.LockRequest {
	return types.LockRequest{
		Locks: lo2.ArrayClone(b.locks),
	}
}

func (b *LockRequestBuilder) MutexLock(svc *distlock.Service, opt ...distlock.AcquireOptionFn) (*distlock.Mutex, error) {
	return svc.Acquire(b.Build(), opt...)
}
