from app.config import Settings


def test_database_server_url_excludes_database_name() -> None:
    settings = Settings.model_construct(
        db_host="127.0.0.1",
        db_port=3306,
        db_name="oreolvpn",
        db_user="user",
        db_password="pass",
    )

    assert settings.database_server_url == "mysql+aiomysql://user:pass@127.0.0.1:3306/?charset=utf8mb4"


def test_support_ticket_link_parses_private_topic_link() -> None:
    settings = Settings.model_construct(
        bot_support_ticket_link="https://t.me/c/3646494169/2/3",
        bot_support_ticket_chat_id_raw="",
        bot_support_ticket_thread_id=0,
    )

    assert settings.support_ticket_chat_id == -1003646494169
    assert settings.support_ticket_message_thread_id == 2


def test_payment_review_link_parses_private_topic_link() -> None:
    settings = Settings.model_construct(
        payment_review_link="https://t.me/c/3646494169/56/57",
        payment_review_chat_id_raw="",
        payment_review_thread_id=0,
    )

    assert settings.payment_review_chat_id == -1003646494169
    assert settings.payment_review_message_thread_id == 56


def test_moderator_ids_are_parsed() -> None:
    settings = Settings.model_construct(
        bot_moderator_ids_raw="123, 456 ,789",
    )

    assert settings.bot_moderator_ids == {123, 456, 789}
    assert settings.is_moderator(456) is True
    assert settings.is_moderator(999) is False


def test_public_username_is_normalized() -> None:
    settings = Settings.model_construct(
        bot_public_username="@oreol_vpn_bot",
    )

    assert settings.bot_public_username_normalized == "oreol_vpn_bot"


def test_payment_internal_squad_uuids_are_parsed() -> None:
    settings = Settings.model_construct(
        payment_internal_squad_uuids_raw="uuid-1, uuid-2 ,uuid-3",
    )

    assert settings.payment_internal_squad_uuids == ["uuid-1", "uuid-2", "uuid-3"]


def test_payment_username_prefix_is_normalized() -> None:
    settings = Settings.model_construct(
        payment_username_prefix="Oreol!! prefix",
    )

    assert settings.payment_username_prefix_normalized == "Oreolprefix"


def test_payment_plans_are_parsed() -> None:
    settings = Settings.model_construct(
        payment_plans_raw="30:250,180:600,365:1000",
    )

    plans = settings.payment_plans

    assert [plan.code for plan in plans] == ["30d", "180d", "365d"]
    assert [plan.days for plan in plans] == [30, 180, 365]
    assert [plan.amount_rub for plan in plans] == [250, 600, 1000]
