"""Solution for the chapter 9 chunking exercise."""

SLACK_ANSWER = "The Slack integration posts task updates to a channel you choose."


def fixed_chunks(text: str, size: int, overlap: int = 0) -> list[str]:
    if size <= 0 or overlap < 0 or overlap >= size:
        raise ValueError("require size > 0 and 0 <= overlap < size")
    chunks = []
    start = 0
    while start < len(text):
        chunks.append(text[start:start + size].strip())
        start += size - overlap
    return chunks


def answer_exists(chunks: list[str], answer: str) -> bool:
    return any(answer in chunk for chunk in chunks)


def whole_answer_first(results: list[dict], answer: str) -> bool:
    return bool(results) and answer in results[0]["text"]
