"""Shared fixtures and sample data for builder loop tests."""

import sys
import textwrap
from pathlib import Path

import pytest

_HERE = Path(__file__).resolve().parent

# Make conftest importable and build-feature modules importable
sys.path.insert(0, str(_HERE))
sys.path.insert(0, str(_HERE.parent / "skills" / "build-feature"))

PROJECT_ID = "test-app"

SAMPLE_TASK = textwrap.dedent("""\
    ---
    id: test-app-scaffold
    title: "Test App — Scaffold"
    parent: test-app
    deps: []
    split: false
    depth: 1
    planned: true
    executed: false
    ---

    ## Overview
    Bootstrap the monorepo.
""")

SAMPLE_ROOT_TASK = textwrap.dedent("""\
    ---
    id: test-app
    title: "Test App"
    parent: null
    deps: []
    split: true
    depth: 0
    planned: true
    ---

    ## Overview
    Root initiative that splits into children.
""")

SAMPLE_UNPLANNED = textwrap.dedent("""\
    ---
    id: test-app-charts
    title: "Test App — Charts"
    parent: test-app
    deps: [test-app-scaffold]
    split: false
    depth: 1
    planned: false
    executed: false
    ---

    ## Overview
    Build the chart view.
""")

SAMPLE_EXECUTED = textwrap.dedent("""\
    ---
    id: test-app-done
    title: "Test App — Done"
    parent: test-app
    deps: []
    split: false
    depth: 1
    planned: true
    executed: true
    ---

    ## Overview
    Already done.
""")

SAMPLE_NO_EXECUTED_FIELD = textwrap.dedent("""\
    ---
    id: test-app-scaffold
    title: "Test App — Scaffold"
    parent: test-app
    deps: []
    split: false
    depth: 1
    planned: true
    ---

    ## Overview
    No executed field at all.
""")


@pytest.fixture
def tasks_dir(tmp_path: Path) -> Path:
    """A single initiative's ``tasks/`` directory (``.autobuilder/initiatives/<NNNN-slug>/tasks/``)."""
    d = tmp_path / ".autobuilder" / "initiatives" / "0001-test-app" / "tasks"
    d.mkdir(parents=True)
    return d


@pytest.fixture
def project_dir(tmp_path: Path) -> Path:
    """Project root with ``.autobuilder/initiatives/`` (empty initiatives container)."""
    d = tmp_path / "project"
    d.mkdir()
    (d / ".autobuilder").mkdir()
    (d / ".autobuilder" / "initiatives").mkdir()
    return d
