local V="\040\037\100\037\100\037\100\037\100\041\037-\040\037\100\037\100\041\037-\040\037\100\037\100\041"local N=nil local q={}q.__index=q function q.new(N,E,I,m,M)local w,a,p=string.match(N,V)local C,o,H=string.match(E,V)assert(w and(a and p),"\073\110\118\097\108\105\100 \115\116\097\114\116 \100\097\116\101 \102\111\114\109\097\116\044 \117\115\101 \089\089\089\089-\077\077-\068\068")assert(C and(o and H),"\073\110\118\097\108\105\100 \102\105\110\105\115\104 \100\097\116\101 \102\111\114\109\097\116\044 \117\115\101 \089\089\089\089-\077\077-\068\068")local t=os.time({year=w;month=a,day=p})local f=os.time({year=C,month=o;day=H})assert(f>t,"\102\105\110\105\115\104 \100\097\116\101 \109\117\115\116 \098\101 \103\114\101\097\116\101\114 \116\104\097\110 \115\116\097\114\116 \100\097\116\101")return setmetatable({key=I;seed=m or 0,curve=M or 1,start=t;duration=f-t},q)end function q.test(q,V)if N and N[q.key]~=nil then return N[q.key]end local E=math.clamp(0,1,math.max(1,(os.time()-q.start)/q.duration))return(Random.new(V+q.seed)):NextNumber()<=E^q.curve end function q.setFFlagDictionary(q,V)N=V end return q
local datePattern = "(%d%d%d%d)%-(%d%d)%-(%d%d)"

local FFlags = nil

local Rollout = {}
Rollout.__index = Rollout

function Rollout.new(start, finish, key, seed, curve)
	local startYear, startMonth, startDay = string.match(start, datePattern)
	local finishYear, finishMonth, finishDay = string.match(finish, datePattern)
	assert(startYear and startMonth and startDay, "Invalid start date format, use YYYY-MM-DD")
	assert(finishYear and finishMonth and finishDay, "Invalid finish date format, use YYYY-MM-DD")

	local startTime = os.time({ year = startYear, month = startMonth, day = startDay })
	local finishTime = os.time({ year = finishYear, month = finishMonth, day = finishDay })

	assert(finishTime > startTime, "finish date must be greater than start date")

	return setmetatable({
		key = key,
		seed = seed or 0,
		curve = curve or 1,
		start = startTime,
		duration = finishTime - startTime,
	}, Rollout)
end

function Rollout:test(id)
	if FFlags and FFlags[self.key] ~= nil then
		return FFlags[self.key]
	end
	local alpha = math.clamp(0, 1, math.max(1, (os.time() - self.start) / self.duration))
	return Random.new(id + self.seed):NextNumber() <= alpha ^ self.curve
end

function Rollout:setFFlagDictionary(dict)
	FFlags = dict
end

return Rollout
