from django.contrib.sitemaps import Sitemap
from django.urls import reverse
from .models import Article, Service


class StaticViewSitemap(Sitemap):
    priority = 0.8
    changefreq = 'weekly'
    protocol = 'https'

    def items(self):
        return ['home', 'about', 'services', 'articles', 'contact', 'gallery']

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


class ArticleSitemap(Sitemap):
    priority = 0.9
    changefreq = 'daily'
    protocol = 'https'

    def items(self):
        return Article.objects.filter(is_published=True)

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

    def location(self, obj):
        return obj.get_absolute_url()


class ServiceSitemap(Sitemap):
    priority = 0.8
    changefreq = 'monthly'
    protocol = 'https'

    def items(self):
        return Service.objects.filter(is_active=True)

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

    def location(self, obj):
        return obj.get_absolute_url()
