from django.shortcuts import render
from django.views import View

from core.lib.manage.threshold import (
    get_irc_channels,
    get_irc_network,
    get_irc_networks,
    get_irc_relays,
    get_irc_stats,
)
from core.views.manage.permissions import SuperUserRequiredMixin


class ThresholdIRCStats(SuperUserRequiredMixin, View):
    stats_template = "dynamic/manage/threshold/irc/overview/stats.html"

    def post(self, request):
        stats = get_irc_stats()
        context = {"stats": stats}
        return render(request, self.stats_template, context)


class ThresholdIRCNetworks(SuperUserRequiredMixin, View):
    template_name = "dynamic/manage/threshold/irc/overview/networks.html"

    def post(self, request):
        networks = get_irc_networks()
        context = {"networks": networks}
        return render(request, self.template_name, context)


class ThresholdIRCNetworkInfo(SuperUserRequiredMixin, View):
    template_name = "dynamic/manage/threshold/irc/network/info.html"

    def post(self, request, net):
        network = get_irc_network(net)
        context = {"network": network}
        return render(request, self.template_name, context)


class ThresholdIRCNetworkRelays(SuperUserRequiredMixin, View):
    template_name = "dynamic/manage/threshold/irc/network/relays.html"

    def post(self, request, net):
        relays = get_irc_relays(net)
        context = {"relays": relays["relays"]}
        return render(request, self.template_name, context)


class ThresholdIRCNetworkChannels(SuperUserRequiredMixin, View):
    template_name = "dynamic/manage/threshold/irc/network/channels.html"

    def post(self, request, net):
        channels = get_irc_channels(net)
        context = {"channels": channels["channels"]}
        return render(request, self.template_name, context)
