from annoying.decorators import render_to
from django.http import HttpRequest, HttpResponse
from django.views.generic import TemplateView
from pytz import UTC


def view_untemplated(request: HttpRequest) -> HttpResponse:
    """Return a base view for demonstration purposes."""
    return HttpResponse("Page content returned")


@render_to("demonstration/basic/plain.txt")
def view_basic_plain(request: HttpRequest) -> dict:
    """Show a plain text rendered as a template."""
    return {}


@render_to("demonstration/basic/variables.html")
def view_basic_variables(request: HttpRequest) -> dict:
    """Show a template using variable interpolation."""
    return {"variable1": "Text number 1.", "variable2": 599.31}


@render_to("demonstration/basic/control.html")
def view_basic_control(request: HttpRequest) -> dict:
    """Use control structures."""
    return {"values": [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]}


@render_to("demonstration/basic/filters.html")
def view_basic_filters(request: HttpRequest) -> dict:
    """Use template filters."""
    from datetime import datetime

    return {"strings": ["text in lowercase", "basic text."], "moment": datetime(2020, 1, 1, tzinfo=UTC)}


@render_to("demonstration/basic/tags.html")
def view_basic_tags(request: HttpRequest) -> dict:
    """Use template tags."""
    return {"numbers": [1, 2, 3, 4, 5, 6, 7, 8]}


class BasicTemplateView(TemplateView):
    """
    Equivalent of the `view_basic_control` view.

    See Also:
        Documentation to know how to use class-based views:
        - https://docs.djangoproject.com/fr/3.2/topics/class-based-views/

    """

    template_name = "demonstration/basic/control.html"
    extra_context = {"values": [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]}
