import { Controller, Get, Query } from '@nestjs/common';
import { ApiTags, ApiOperation } from '@nestjs/swagger';
import { NetworkService } from './network.service';
import { NetworkRangeDto } from './dto/network-query.dto';

@ApiTags('Network')
@Controller('network')
export class NetworkController {
  constructor(private readonly networkService: NetworkService) {}

  @Get('corps')
  @ApiOperation({
    summary: 'Per-corp totals (visitors + pageviews) over a rolling window',
  })
  async corps(@Query() q: NetworkRangeDto) {
    return this.networkService.getCorps(q.days ?? 7);
  }

  @Get('domains')
  @ApiOperation({
    summary: 'Per-domain traffic table grouped by corp',
  })
  async domains(@Query() q: NetworkRangeDto) {
    return this.networkService.getDomains(q.days ?? 7);
  }

  @Get('flow')
  @ApiOperation({
    summary: 'Sankey edges: visitors flowing corp A → corp B',
    description:
      'For each visitor_id_daily, walks events in time order and counts ' +
      'consecutive transitions between distinct corps. Returns directed edges.',
  })
  async flow(@Query() q: NetworkRangeDto) {
    return this.networkService.getFlow(q.days ?? 7);
  }

  @Get('overlap')
  @ApiOperation({
    summary: 'Symmetric overlap: visitors who touched BOTH corps in the window',
    description: 'Upper triangle only (corp_a_id < corp_b_id).',
  })
  async overlap(@Query() q: NetworkRangeDto) {
    return this.networkService.getOverlap(q.days ?? 7);
  }
}
