# -*- coding: utf-8 -*-
from __future__ import annotations

from django.contrib.auth import REDIRECT_FIELD_NAME
from django.contrib.auth.decorators import user_passes_test

from .checks import is_authenticated_and_active_account


def account_required(function=None,
                     redirect_field_name=REDIRECT_FIELD_NAME,
                     login_url=None,
                     ):
    actual_decorator = user_passes_test(
        is_authenticated_and_active_account,
        login_url=login_url,
        redirect_field_name=redirect_field_name,
    )

    if function:
        return actual_decorator(function)

    return actual_decorator
