import { Controller, Get, Header, Param, ParseIntPipe } from '@nestjs/common';
import { SitemapService } from './sitemap.service';

@Controller()
export class SitemapController {
  constructor(private readonly sitemapService: SitemapService) { }

  /**
   * Main sitemap index - lists all sitemap files
   * Route: /sitemap.xml
   */
  @Get('sitemap.xml')
  @Header('Content-Type', 'application/xml')
  @Header('Cache-Control', 'public, max-age=3600')
  async getSitemapIndex(): Promise<string> {
    return await this.sitemapService.generateSitemapIndex();
  }

  /**
   * Static pages sitemap
   * Route: /sitemap/static.xml
   */
  @Get('sitemap/static.xml')
  @Header('Content-Type', 'application/xml')
  @Header('Cache-Control', 'public, max-age=3600')
  async getStaticSitemap(): Promise<string> {
    return await this.sitemapService.generateStaticSitemap();
  }

  /**
   * Business listings sitemap (paginated)
   * Route: /sitemap/business-1.xml, /sitemap/business-2.xml, etc.
   */
  @Get('sitemap/business-:page.xml')
  @Header('Content-Type', 'application/xml')
  @Header('Cache-Control', 'public, max-age=3600')
  async getBusinessSitemap(@Param('page', ParseIntPipe) page: number): Promise<string> {
    return await this.sitemapService.generateBusinessSitemap(page);
  }

  /**
   * Commercial property sitemap (paginated)
   * Route: /sitemap/commercial-1.xml, /sitemap/commercial-2.xml, etc.
   */
  @Get('sitemap/commercial-:page.xml')
  @Header('Content-Type', 'application/xml')
  @Header('Cache-Control', 'public, max-age=3600')
  async getCommercialSitemap(@Param('page', ParseIntPipe) page: number): Promise<string> {
    return await this.sitemapService.generateCommercialSitemap(page);
  }

  /**
   * Broker profiles sitemap (paginated)
   * Route: /sitemap/brokers-1.xml, /sitemap/brokers-2.xml, etc.
   */
  @Get('sitemap/brokers-:page.xml')
  @Header('Content-Type', 'application/xml')
  @Header('Cache-Control', 'public, max-age=3600')
  async getBrokerSitemap(@Param('page', ParseIntPipe) page: number): Promise<string> {
    return await this.sitemapService.generateBrokerSitemap(page);
  }
}
