import sys
from pathlib import Path

import numpy as np
import pytest

sys.path.insert(0, str(Path(__file__).resolve().parent.parent))

from delivery.travel_time import TimeModel  # noqa: E402


def synthetic_matrix(Z=8, seed=0, rush=True):
    """Time-dependent synthetic matrix: zones in the plane, rush hours slower."""
    rng = np.random.default_rng(seed)
    xy = rng.uniform(0, 5, size=(Z, 2))
    d = np.linalg.norm(xy[:, None] - xy[None], axis=2)
    base = 4.0 + 3.0 * d
    mult = np.ones(24)
    if rush:
        mult[7:10] = 1.35
        mult[16:19] = 1.4
        mult[0:6] = 0.8
    return base[None] * mult[:, None, None]


@pytest.fixture
def tm():
    return TimeModel(synthetic_matrix(), factor=1.0, name="synthetic")


def line_tm(n=5, per_step=5.0, plus=1.0):
    idx = np.arange(n)
    M = per_step * np.abs(idx[:, None] - idx[None]) + plus
    return TimeModel(M, factor=1.0, name="line")
