import { Controller, Get, Query } from '@nestjs/common';
import {
  AcquisitionService,
  AcquisitionOverview,
  ChannelMetrics,
  SourceMetrics,
  CampaignMetrics,
  ReferrerMetrics,
  AcquisitionComparison,
} from './acquisition.service';
import { AcquisitionQueryDto, AcquisitionCompareDto, ReferrerQueryDto } from './dto/acquisition-query.dto';

@Controller('acquisition')
export class AcquisitionController {
  constructor(private readonly acquisitionService: AcquisitionService) {}

  /**
   * Get acquisition overview
   * GET /acquisition/overview?startDate=2024-01-01&endDate=2024-01-31
   */
  @Get('overview')
  async getOverview(@Query() query: AcquisitionQueryDto): Promise<AcquisitionOverview> {
    return this.acquisitionService.getOverview(query);
  }

  /**
   * Get channel breakdown
   * GET /acquisition/channels?startDate=2024-01-01&endDate=2024-01-31
   */
  @Get('channels')
  async getChannels(@Query() query: AcquisitionQueryDto): Promise<ChannelMetrics[]> {
    return this.acquisitionService.getChannels(query);
  }

  /**
   * Get source/medium breakdown
   * GET /acquisition/sources?startDate=2024-01-01&endDate=2024-01-31&channel=organic
   */
  @Get('sources')
  async getSources(@Query() query: AcquisitionQueryDto): Promise<SourceMetrics[]> {
    return this.acquisitionService.getSources(query);
  }

  /**
   * Get campaign performance
   * GET /acquisition/campaigns?startDate=2024-01-01&endDate=2024-01-31
   */
  @Get('campaigns')
  async getCampaigns(@Query() query: AcquisitionQueryDto): Promise<CampaignMetrics[]> {
    return this.acquisitionService.getCampaigns(query);
  }

  /**
   * Get top referrers
   * GET /acquisition/referrers?startDate=2024-01-01&endDate=2024-01-31&limit=20
   */
  @Get('referrers')
  async getReferrers(@Query() query: ReferrerQueryDto): Promise<ReferrerMetrics[]> {
    return this.acquisitionService.getReferrers(query);
  }

  /**
   * Compare acquisition between two periods
   * GET /acquisition/compare?startDate=2024-01-01&endDate=2024-01-31&compareStartDate=2023-12-01&compareEndDate=2023-12-31
   */
  @Get('compare')
  async compare(@Query() query: AcquisitionCompareDto): Promise<AcquisitionComparison> {
    return this.acquisitionService.compare(query);
  }
}
