"""Deployment safety checks for the intentionally non-production provider."""

import sys

from django.conf import settings
from django.core.checks import Error, Tags, register


@register(Tags.security)
def dummy_payment_is_explicitly_allowed(app_configs, **kwargs):
    """Reject dummy payments outside DEBUG unless an environment opted in explicitly."""
    is_django_test_run = "test" in sys.argv
    if (
        settings.DEBUG
        or is_django_test_run
        or getattr(settings, "OCYAN_DUMMY_PAYMENT_ALLOWED", False)
    ):
        return []

    return [
        Error(
            "Dummy payment is enabled outside a development or test configuration.",
            hint=(
                "Remove ocyan.plugin.payment_dummy for production. Set "
                "OCYAN_DUMMY_PAYMENT_ALLOWED=True only for an explicitly "
                "non-production demo or preview environment."
            ),
            id="payment_dummy.E001",
        )
    ]
