from django.contrib.sitemaps import Sitemap
from django.urls import reverse
from .models import Home, Solution, Competence, Recall

class StaticViewSitemap(Sitemap):
    priority = 1.0
    changefreq = 'monthly'

    def items(self):
        return ['home', 'about', 'solution', 'ability', 'recall']

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

class HomeSitemap(Sitemap):
    changefreq = 'weekly'
    priority = 1.0

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

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

    # УБИРАЕМ метод location - используем default
    # Django автоматически сгенерирует правильные URL

class SolutionSitemap(Sitemap):
    changefreq = 'weekly'
    priority = 0.9

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

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

class CompetenceSitemap(Sitemap):
    changefreq = 'monthly'
    priority = 0.8

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

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

class RecallSitemap(Sitemap):
    changefreq = 'monthly'
    priority = 0.7

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

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

# Упрощаем sitemaps - убираем HomeSitemap если он дублирует главную
sitemaps = {
    'static': StaticViewSitemap,
    'solutions': SolutionSitemap,
    'competence': CompetenceSitemap,
    'recall': RecallSitemap,
}