macro decision(def...) @warn "@decision should be used inside a @stage block." end
"""
    @recourse(model, expr, args..., kw_args...)
Add a recourse decision variable to `model` described by the expression `expr`. Replaces [`@decision`](@ref) in the [`@stage`](@ref) block of the final stage, and can only be used there. See `@variable` for syntax details.
## Examples
```julia
@recourse(model, 0 <= y <= 1)
```
See also [`@decision`](@ref), [`@parameters`](@ref), [`@uncertain`](@ref), [`@stage`](@ref)
"""
macro recourse(def...) @warn "@recourse should be used inside the @stage block of the final stage." end
macro _decision(args...)
    args = [args...]
    known = false
    recourse = false
    # Check context of decision definition
    if args[1] isa Symbol && args[1] == :known
        known = true
    elseif args[1] isa Symbol && args[1] == :recourse
        recourse = true
    else
        args[1] == :decision || error("Incorrect usage of @_decision.")
    end
    # Remove context from args
    deleteat!(args, 1)
    # Cache stage and remove from args
    stage = args[1]
    deleteat!(args, 1)
    # Move any set definitions
    set = NoSpecifiedConstraint()
    for (i, arg) in enumerate(args)
        set, arg, found = extract_set(arg)
        if found
            if arg == :()
                deleteat!(args, i)
            else
                args[i] = arg
            end
            break
        end
    end
    # Return expression based on context
    if known
        return esc(:(@variable $((args)...) set = StochasticPrograms.KnownSet($stage)))
    else
        return esc(:(@variable $((args)...) set = StochasticPrograms.DecisionSet($stage, constraint = $set, is_recourse = $recourse)))
    end
end
"""
    @known(def)
Annotate each decision taken in the previous stage. Any [`@decision`](@ref) included in a [`@stochastic_model`](@ref) definition will implicitly add `@known` annotations to subsequent stages.
## Examples
```julia
@known x₁, x₂
```
See also [`@decision`](@ref), [`@parameters`](@ref), [`@uncertain`](@ref), [`@stage`](@ref)
"""
macro known(model_name, args...)
    code = Expr(:block)
    for var in args
        varkey = Meta.quot(var)
        push!(code.args, :($(esc(var)) = $(esc(model_name))[$varkey]))
    end
    return code
end