"""Test that fixtures work correctly."""

from pathlib import Path
import pytest

from ghostty_tui.models import ConfigValue, OptionDefinition, OptionModel, OptionType
from ghostty_tui.parser import GhosttyParser


def test_sample_schema_path(sample_schema_path):
    """Test sample_schema_path fixture."""
    assert isinstance(sample_schema_path, Path)
    assert sample_schema_path.exists()
    assert sample_schema_path.name == "ghostty_schema_sample.txt"


def test_sample_schema(sample_schema):
    """Test sample_schema fixture."""
    assert isinstance(sample_schema, str)
    assert len(sample_schema) > 0


def test_parser(parser):
    """Test parser fixture."""
    assert isinstance(parser, GhosttyParser)


def test_parsed_options(parsed_options):
    """Test parsed_options fixture."""
    assert isinstance(parsed_options, list)
    assert len(parsed_options) > 0
    assert all(isinstance(opt, OptionDefinition) for opt in parsed_options)


def test_options_dict(options_dict):
    """Test options_dict fixture."""
    assert isinstance(options_dict, dict)
    assert len(options_dict) > 0
    assert all(isinstance(k, str) for k in options_dict.keys())
    assert all(isinstance(v, OptionDefinition) for v in options_dict.values())


def test_tmp_config_file(tmp_config_file):
    """Test tmp_config_file fixture."""
    assert isinstance(tmp_config_file, Path)
    assert tmp_config_file.exists()
    content = tmp_config_file.read_text()
    assert "font-size = 14" in content
    assert "cursor-style = bar" in content
    assert "window-title = Test Terminal" in content


def test_tmp_config_dir(tmp_config_dir):
    """Test tmp_config_dir fixture."""
    assert isinstance(tmp_config_dir, Path)
    assert tmp_config_dir.exists()
    assert tmp_config_dir.is_dir()


def test_option_factory(option_factory):
    """Test option_factory fixture."""
    opt = option_factory(
        name="test-option",
        option_type=OptionType.BOOLEAN,
        default_value="true"
    )
    assert isinstance(opt, OptionDefinition)
    assert opt.name == "test-option"
    assert opt.option_type == OptionType.BOOLEAN
    assert opt.default_value == "true"


def test_config_value_factory(config_value_factory):
    """Test config_value_factory fixture."""
    val = config_value_factory(
        name="test-option",
        value="test-value",
        line_number=5,
        is_modified=True
    )
    assert isinstance(val, ConfigValue)
    assert val.name == "test-option"
    assert val.value == "test-value"
    assert val.line_number == 5
    assert val.is_modified is True


def test_option_model_factory(option_model_factory):
    """Test option_model_factory fixture."""
    model = option_model_factory(
        name="test-option",
        option_type=OptionType.INTEGER,
        default_value="10",
        current_value="20",
        is_modified=True
    )
    assert isinstance(model, OptionModel)
    assert model.definition.name == "test-option"
    assert model.definition.option_type == OptionType.INTEGER
    assert model.current.value == "20"
    assert model.current.is_modified is True


def test_mock_ghostty_output(mock_ghostty_output):
    """Test mock_ghostty_output fixture."""
    assert isinstance(mock_ghostty_output, str)
    assert "font-size = 12" in mock_ghostty_output
    assert "cursor-style = block" in mock_ghostty_output
    assert "cursor-blink = false" in mock_ghostty_output


def test_sample_options_dict(sample_options_dict):
    """Test sample_options_dict fixture."""
    assert isinstance(sample_options_dict, dict)
    assert len(sample_options_dict) == 4

    # Check boolean option
    assert "cursor-blink" in sample_options_dict
    opt = sample_options_dict["cursor-blink"]
    assert opt.definition.option_type == OptionType.BOOLEAN
    assert opt.current.value == "false"

    # Check integer option
    assert "font-size" in sample_options_dict
    opt = sample_options_dict["font-size"]
    assert opt.definition.option_type == OptionType.INTEGER
    assert opt.current.value == "14"
    assert opt.current.is_modified is True

    # Check enum option
    assert "cursor-style" in sample_options_dict
    opt = sample_options_dict["cursor-style"]
    assert opt.definition.option_type == OptionType.ENUM
    assert opt.definition.enum_values == ("block", "bar", "underline")
    assert opt.current.value == "bar"

    # Check string option
    assert "window-title" in sample_options_dict
    opt = sample_options_dict["window-title"]
    assert opt.definition.option_type == OptionType.STRING
    assert opt.current.value is None


def test_tmp_config_file_cleanup(tmp_config_file):
    """Test that tmp_config_file cleans up after test."""
    # File should exist during test
    assert tmp_config_file.exists()

    # Store path for later check
    path = tmp_config_file

    # After this test completes, pytest will run cleanup
    # We can't directly test cleanup here, but we verify it exists now
    assert path.exists()
