from django.contrib.sitemaps import Sitemap
from django.urls import reverse
from hub.services.models import (
    Service,
    CloudProvider,
    ConsultingPartner,
    ServiceOffering,
)


class StaticSitemap(Sitemap):
    changefreq = "monthly"
    priority = 1.0

    def items(self):
        return ["services:homepage", "services:contact"]

    def location(self, item):
        return reverse(item)


class ServiceSitemap(Sitemap):
    changefreq = "weekly"
    priority = 1.0

    def items(self):
        return Service.objects.filter(disable_listing=False).exclude(
            is_coming_soon=True
        )

    def lastmod(self, obj):
        return obj.updated_at


class OfferingSitemap(Sitemap):
    changefreq = "weekly"
    priority = 0.7

    def items(self):
        return ServiceOffering.objects.filter(disable_listing=False)

    def lastmod(self, obj):
        return obj.updated_at


class CloudProviderSitemap(Sitemap):
    changefreq = "weekly"
    priority = 0.7

    def items(self):
        return CloudProvider.objects.filter(disable_listing=False)


class ConsultingPartnerSitemap(Sitemap):
    changefreq = "weekly"
    priority = 0.7

    def items(self):
        return ConsultingPartner.objects.filter(disable_listing=False)

    def lastmod(self, obj):
        return obj.updated_at
