package poem

default allow := false

allow if {
    text := lower(input.output.poem)
    words := regex.find_n(`[\p{L}\p{M}\p{N}_]+`, text, -1)
    count([word | some word in words; word == "roses"]) == 3
    count([word | some word in words; word == "calm"]) == 1
    count(split(text, "e")) - 1 == 12
}

# Explicitly exported guidance; never an alternative authorization decision.
feedback := [{
    "code": "letter_count",
    "scope": ["poem"],
    "message": sprintf("The rejected poem contained %d occurrences of the letter e; exactly 12 are required. The retained string prefix contains %d, so its continuation needs %d more. The completed poem must also contain roses exactly three times and calm exactly once. Do not close the string before satisfying all counts.", [failed, retained, 12-retained]),
}] if {
    failed := count(split(lower(input.output.poem), "e")) - 1
    retained := count(split(lower(object.get(input.repair, "string_prefix", "")), "e")) - 1
}
