from devplacepy.utils import hash_password, verify_password, generate_uid, slugify, time_ago
from datetime import datetime, timedelta, timezone


def test_hash_password_returns_string():
    result = hash_password("test123")
    assert isinstance(result, str)
    assert len(result) > 20


def test_verify_password_correct():
    hashed = hash_password("correct-password")
    assert verify_password("correct-password", hashed) is True


def test_verify_password_wrong():
    hashed = hash_password("correct-password")
    assert verify_password("wrong-password", hashed) is False


def test_generate_uid_is_unique():
    uid1 = generate_uid()
    uid2 = generate_uid()
    assert uid1 != uid2


def test_generate_uid_format():
    uid = generate_uid()
    assert isinstance(uid, str)
    assert len(uid) == 36  # UUID v4 format


def test_slugify_basic():
    assert slugify("Hello World") == "hello-world"


def test_slugify_special_chars():
    assert slugify("Hello! World???") == "hello-world"


def test_slugify_multiple_dashes():
    assert slugify("hello---world") == "hello-world"


def test_slugify_leading_trailing():
    assert slugify("--hello--") == "hello"


def test_time_ago_just_now():
    now = datetime.now(timezone.utc).isoformat()
    result = time_ago(now)
    assert result == "just now"


def test_time_ago_minutes():
    dt = (datetime.now(timezone.utc) - timedelta(minutes=5)).isoformat()
    result = time_ago(dt)
    assert "m ago" in result


def test_time_ago_hours():
    dt = (datetime.now(timezone.utc) - timedelta(hours=3)).isoformat()
    result = time_ago(dt)
    assert "h ago" in result


def test_time_ago_days():
    dt = (datetime.now(timezone.utc) - timedelta(days=5)).isoformat()
    result = time_ago(dt)
    assert "d ago" in result


def test_time_ago_months():
    dt = (datetime.now(timezone.utc) - timedelta(days=60)).isoformat()
    result = time_ago(dt)
    assert "/" in result


def test_time_ago_years():
    dt = (datetime.now(timezone.utc) - timedelta(days=400)).isoformat()
    result = time_ago(dt)
    assert "/" in result
