import { Controller, Get, Query } from '@nestjs/common';
import { ApiTags, ApiOperation, ApiQuery, ApiResponse } from '@nestjs/swagger';
import { HomeService } from './home.service';
import { UspTextEntity } from 'src/entities/UspText.entity';
import { UspCountEntity } from 'src/entities/UspCount.entity';
import { UspTextDescriptionEntity } from 'src/entities/UspTextDescription.entity';
import { WebBannerDetailsEntity } from 'src/entities/WebBannerDetails.entity';
import { GetWebMediaDto } from './dto/search-web-media.dto';
import { OurProductsEntity } from 'src/entities/OurProducts.entity';

/**
 * HomeController - Controller for homepage and public-facing content
 *
 * This controller handles all public endpoints for retrieving homepage content,
 * marketing materials, testimonials, and other front-facing content.
 * All endpoints are publicly accessible and don't require authentication.
 *
 * Features:
 * - USP (Unique Selling Proposition) content
 * - Web banners and media galleries
 * - Testimonials and accolades
 * - Country and product listings
 * - TV shows and multimedia content
 *
 * @example
 * // Base URL endpoints
 * GET /usp-text-description
 * GET /banners?pageType=homepage
 * GET /web-media?upload_time=week&type=1
 */
@ApiTags('Home') // Groups endpoints under 'Home' in Swagger UI
@Controller('') // Empty controller path means routes are at root level
export class HomeController {
  constructor(private readonly service: HomeService) {}

  /**
   * Get USP text descriptions
   *
   * Retrieves descriptive text for Unique Selling Propositions based on
   * page type and optional identifier.
   *
   * @param pageType - The page/section type (e.g., 'homepage', 'about')
   * @param id - Optional identifier for specific USP description
   * @returns Single USP text description entity
   *
   * @example
   * GET /usp-text-description?pageType=homepage
   */
  @Get('usp-text-description')
  @ApiOperation({
    summary: 'Get USP text description',
    description:
      'Retrieve Unique Selling Proposition text description for a specific page',
  })
  @ApiQuery({
    name: 'pageType',
    required: false,
    description: 'Page type (e.g., homepage, about)',
  })
  @ApiQuery({
    name: 'id',
    required: false,
    description: 'Specific USP description ID',
  })
  @ApiResponse({
    status: 200,
    description: 'USP text description retrieved successfully',
  })
  async getUspTextDescription(
    @Query('pageType') pageType?: string,
    @Query('id') id?: string,
  ): Promise<UspTextDescriptionEntity> {
    return this.service.getUspTextDescriptionByPageTypeFrontend(pageType, id);
  }

  /**
   * Get all active USP texts
   *
   * Retrieves all Unique Selling Proposition texts for a given page type
   * and optional country filter.
   *
   * @param pageType - The page/section type
   * @param visaProductCountryId - Optional country ID for country-specific USPs
   * @returns Array of USP text entities
   *
   * @example
   * GET /usp-text?pageType=services&visaProductCountryId=44
   */
  @Get('usp-text')
  @ApiOperation({
    summary: 'Get all USP texts',
    description: 'Retrieve all active Unique Selling Proposition texts',
  })
  async getUspText(
    @Query('pageType') pageType?: string,
    @Query('visaProductCountryId') visaProductCountryId?: number,
  ): Promise<UspTextEntity[]> {
    return this.service.getAllActiveUspTextFrontend(
      pageType,
      visaProductCountryId,
    );
  }

  /**
   * Get USP counts/statistics
   *
   * Retrieves statistical data or counts for Unique Selling Propositions.
   *
   * @param pageType - The page/section type
   * @param visaProductCountryId - Optional country ID for country-specific counts
   * @returns Array of USP count entities
   *
   * @example
   * GET /usp-count?pageType=homepage
   */
  @Get('usp-count')
  @ApiOperation({
    summary: 'Get USP counts',
    description: 'Retrieve statistical counts for Unique Selling Propositions',
  })
  async getUspCounts(
    @Query('pageType') pageType?: string,
    @Query('visaProductCountryId') visaProductCountryId?: number,
  ): Promise<UspCountEntity[]> {
    return this.service.getAllActiveUspCountsFrontend(
      pageType,
      visaProductCountryId,
    );
  }

  /**
   * Get marquee/offers content
   *
   * Retrieves scrolling marquee or offer content for display.
   *
   * @returns Array of marquee/offer items
   *
   * @example
   * GET /marquee
   */
  @Get('marquee')
  @ApiOperation({
    summary: 'Get marquee offers',
    description: 'Retrieve scrolling marquee or promotional offers',
  })
  findAll(): Promise<any> {
    return this.service.getOfferMarqueeFrontend(3); // 3 might be limit or type
  }

  /**
   * Get web banners
   *
   * Retrieves banner images/content for web pages.
   *
   * @param pageType - The page/section type for contextual banners
   * @param id - Optional specific banner ID
   * @returns Array of web banner entities
   *
   * @example
   * GET /banners?pageType=homepage
   */
  @Get('banners')
  @ApiOperation({
    summary: 'Get web banners',
    description: 'Retrieve banner images/content for web pages',
  })
  async getBanners(
    @Query('pageType') pageType?: string,
    @Query('id') id?: number,
  ): Promise<WebBannerDetailsEntity[]> {
    return this.service.getAllActiveWebBannersFrontend(pageType, id);
  }

  /**
   * Get all countries
   *
   * Retrieves list of countries for selection or display.
   *
   * @returns List of countries
   *
   * @example
   * GET /countries
   */
  @Get('countries')
  @ApiOperation({
    summary: 'Get countries list',
    description: 'Retrieve list of all available countries',
  })
  async getCountriesAll() {
    return this.service.getCountries();
  }

  /**
   * Get testimonials
   *
   * Retrieves customer testimonials for display.
   *
   * @param pageType - The page/section type for contextual testimonials
   * @param visaProductCountryId - Optional country ID for country-specific testimonials
   * @returns Array of testimonial data
   *
   * @example
   * GET /testimonials?pageType=homepage
   */
  @Get('testimonials')
  @ApiOperation({
    summary: 'Get testimonials',
    description: 'Retrieve customer testimonials',
  })
  async getTestimonials(
    @Query('pageType') pageType?: string,
    @Query('visaProductCountryId') visaProductCountryId?: number,
  ) {
    return this.service.getTextualTestimonialShortFrontend(
      pageType,
      visaProductCountryId,
    );
  }

  /**
   * Get accolades/awards
   *
   * Retrieves company accolades, awards, or achievements.
   *
   * @param pageType - The page/section type for contextual accolades
   * @param visaProductCountryId - Optional country ID for country-specific accolades
   * @returns Array of accolade data
   *
   * @example
   * GET /accolades?pageType=about
   */
  @Get('accolades')
  @ApiOperation({
    summary: 'Get accolades',
    description: 'Retrieve company awards and achievements',
  })
  async getAccolades(
    @Query('pageType') pageType?: string,
    @Query('visaProductCountryId') visaProductCountryId?: number,
  ) {
    return this.service.getActiveAccoladesFrontend(
      pageType,
      visaProductCountryId,
    );
  }

  /**
   * Get filtered web media
   *
   * Retrieves media content (images, videos) with flexible filtering options.
   *
   * @param query - Filtering parameters (type, timeframe, search, etc.)
   * @returns Filtered media content
   *
   * @example
   * GET /web-media?upload_time=week&type=1&search_text=travel
   */
  @Get('web-media')
  @ApiOperation({
    summary: 'Get web media',
    description: 'Retrieve filtered media content (images, videos)',
  })
  getAllWebMedia(@Query() query: GetWebMediaDto) {
    return this.service.getAllWebMedia(query);
  }

  /**
   * Get our products
   *
   * Retrieves active product listings.
   *
   * @param pageType - The page/section type for contextual products
   * @param visaProductCountryId - Optional country ID for country-specific products
   * @returns Array of product entities
   *
   * @example
   * GET /our-products?pageType=services
   */
  @Get('our-products')
  @ApiOperation({
    summary: 'Get our products',
    description: 'Retrieve active product listings',
  })
  async getAllOurProductsShortActiveFrontend(
    @Query('pageType') pageType?: string,
    @Query('visaProductCountryId') visaProductCountryId?: number,
  ): Promise<OurProductsEntity[]> {
    return this.service.getAllOurProductsShortActiveFrontend(
      pageType,
      visaProductCountryId,
    );
  }

  /**
   * Get TV shows
   *
   * Retrieves TV show or video content.
   *
   * @param pageType - The page/section type for contextual TV shows
   * @returns Array of TV show data
   *
   * @example
   * GET /tv-shows?pageType=media
   */
  @Get('tv-shows')
  @ApiOperation({
    summary: 'Get TV shows',
    description: 'Retrieve TV show or video content',
  })
  async getShortActiveTvShows(@Query('pageType') pageType?: string) {
    return this.service.getAllTvShowsShortActiveFrontend(pageType);
  }
}
