#!/usr/bin/env python3
"""Infrastructure層テスト用共通フィクスチャ

リポジトリ実装やアダプターテストで使用する共通フィクスチャ群
"""

from collections.abc import Generator
from pathlib import Path
from typing import Any

import pytest

from noveler.presentation.shared.shared_utilities import get_common_path_service


@pytest.fixture
def temp_dir(tmp_path_factory: pytest.TempPathFactory) -> Generator[Path, None, None]:
    """Create an isolated temporary directory for infrastructure unit tests.

    Purpose:
        Supply filesystem-backed tests with a unique workspace that is managed by pytest.

    Args:
        tmp_path_factory: Factory responsible for producing temporary directories anchored
            under pytest's basetemp.

    Yields:
        Path: Absolute path to the created directory.
    Side Effects:
        Creates the directory; cleanup is automatically handled by pytest.
    """
    raw_dir = tmp_path_factory.mktemp("novel_test", numbered=True)
    return Path(str(raw_dir))


@pytest.fixture
def temp_project_dir(temp_dir) -> Path:
    """一時プロジェクトディレクトリ"""
    project_dir = temp_dir / "test_project"
    project_dir.mkdir()

    # 基本的なプロジェクト構造を作成
    path_service = get_common_path_service()
    (project_dir / str(path_service.get_manuscript_dir())).mkdir()
    (project_dir / "プロジェクト設定.yaml").write_text(
        "title: テストプロジェクト\nauthor: テスト作者\n", encoding="utf-8"
    )

    return project_dir


@pytest.fixture
def yaml_test_data() -> dict[str, Any]:
    """YAML テスト用データ"""
    return {
        "test_episode": {"episode_number": 1, "title": "テストエピソード", "word_count": 3000, "status": "draft"},
        "test_project": {"title": "テストプロジェクト", "author": "テスト作者", "genre": "ファンタジー"},
    }
