from django.contrib.sitemaps import Sitemap
from .models import *
from django.http import HttpResponse
from django.contrib.sites.models import Site

class CeremonySitemap(Sitemap):
    changefreq = "weekly"
    priority = 1.0

    def items(self):
        return Ceremony.objects.all()

    def lastmod(self, obj):
        return obj.created_at

    def location(self, obj):
        return reverse('ceremony_detail', kwargs={'pk': obj.id})
    
    
class CategorySitemap(Sitemap):
    changefreq = "monthly"
    priority = 0.8

    def items(self):
        return CeremonyCategory.objects.all()

    def lastmod(self, obj):
        return obj.created_at

    def location(self, obj):
        return reverse('category_detail', kwargs={'parent_id': obj.id})
    
    
class AudioSitemap(Sitemap):
    changefreq = "weekly"
    priority = 0.9

    def items(self):
        return CeremonyFile.objects.filter(file_type='audio')

    def lastmod(self, obj):
        return obj.uploaded_at

    def location(self, obj):
        return reverse('audio_detail', kwargs={'pk': obj.id})
    
class VideoSitemap(Sitemap):
    changefreq = "weekly"
    priority = 0.9

    def items(self):
        return CeremonyFile.objects.filter(file_type='video')

    def lastmod(self, obj):
        return obj.uploaded_at

    def location(self, obj):
        return reverse('video_detail', kwargs={'pk': obj.id})
    
    
class ListPagesSitemap(Sitemap):
    changefreq = "weekly"
    priority = 0.6

    def items(self):
        return [
            'category_list',
            'ceremony_list',
            'audios_list',
            'videos_list',
            'ring_back_tone_list',
        ]

    def location(self, item):
        return reverse(item)
    
    
def robots_txt(request):
    site = Site.objects.get_current()

    sitemap_url = f"https://{site.domain}/sitemap.xml"

    text = f"""
User-agent: *
Allow: /

Disallow: /dashboard/
Disallow: /admin/

Sitemap: {sitemap_url}
"""

    return HttpResponse(text, content_type="text/plain")


from django.contrib.sitemaps import Sitemap
from django.urls import reverse


class GeneralPagesSitemap(Sitemap):
    changefreq = "monthly"
    priority = 0.4

    def items(self):
        return [
            'home',
            'about',
            'contact',
            'designer',
            'bio',
        ]

    def location(self, item):
        return reverse(item)