#!/usr/bin/python3
"""Shared pytest fixtures for the sbo-create test suite."""

import shutil
from pathlib import Path

import pytest

from sbo_create.models import AppContext, MaintainerData, InfoData, set_x86_labels


BUNDLED_TEMPLATES: Path = Path(__file__).parent / 'templates'

SAMPLE_PRGNAM: str = 'myapp'
SAMPLE_VERSION: str = '1.2.3'
SAMPLE_MAINTAINER: str = 'John Doe'
SAMPLE_EMAIL: str = 'john@example.com'
SAMPLE_LOCATION: str = 'Nowhere'
SAMPLE_YEAR: int = 2025


@pytest.fixture
def tmp_templates(tmp_path: Path) -> Path:
    """Copy bundled templates to a temporary directory and return its path."""
    dest: Path = tmp_path / 'templates'
    shutil.copytree(str(BUNDLED_TEMPLATES), str(dest))
    return dest


@pytest.fixture
def ctx(tmp_templates: Path) -> AppContext:
    """Return a populated AppContext pointing to the temporary templates directory."""
    app_ctx = AppContext()
    app_ctx.prg_name = SAMPLE_PRGNAM
    app_ctx.year = SAMPLE_YEAR
    app_ctx.templates_path = tmp_templates
    app_ctx.repo_path = tmp_templates.parent / 'repo'
    app_ctx.maintainer = MaintainerData(
        name=SAMPLE_MAINTAINER,
        email=SAMPLE_EMAIL,
        where_you_live=SAMPLE_LOCATION,
    )
    app_ctx.info = InfoData(version=SAMPLE_VERSION)
    set_x86_labels(app_ctx.info)
    return app_ctx
