import inject
from litestar import (
    Controller,
    MediaType,
    get,
)

from server.modules.descriptions import Breed, CharactersService


class SeoController(Controller):
    @get("/sitemap.xml", media_type=MediaType.XML)
    async def sitemaps(self) -> bytes:
        characters_service: CharactersService = inject.instance(CharactersService)
        breeds: list[Breed] = await characters_service.get_characters("dog")
        lastmod = "2026-01-15T19:01:03+00:00"
        beers_url = ""
        for b in breeds:
            beers_url += f"""
<url>
  <loc>https://xn-----6kcp3cadbabfh8a0a.xn--p1ai/dogs-characteristics/{b.alias}</loc>
  <lastmod>{lastmod}</lastmod>
</url>
"""
        return f"""<?xml version="1.0" encoding="UTF-8"?>
<urlset
      xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
            http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
<!-- created with Free Online Sitemap Generator www.xml-sitemaps.com -->


<url>
  <loc>https://xn-----6kcp3cadbabfh8a0a.xn--p1ai/</loc>
  <lastmod>{lastmod}</lastmod>
</url>
<url>
  <loc>https://xn-----6kcp3cadbabfh8a0a.xn--p1ai/cats</loc>
  <lastmod>{lastmod}</lastmod>
</url>
<url>
  <loc>https://xn-----6kcp3cadbabfh8a0a.xn--p1ai/donate</loc>
  <lastmod>{lastmod}</lastmod>
</url>
<url>
  <loc>https://xn-----6kcp3cadbabfh8a0a.xn--p1ai/dogs-characteristics</loc>
  <lastmod>{lastmod}</lastmod>
</url>
{beers_url}

</urlset>
""".encode()

    @get("/robots.txt", media_type=MediaType.TEXT)
    async def robots(self) -> str:
        return """
User-agent: *
Allow: /

Sitemap: https://xn-----6kcp3cadbabfh8a0a.xn--p1ai/sitemap.xml
"""
