import { Args, Query, Resolver, Subscription } from '@nestjs/graphql';
import {
  TimePerTourKPISummaryObjectType,
  TimePerTourMetricObjectType,
  TimePerTourUpdateObjectType,
} from './manager.object-type';
import { TimePerTourKpiService } from './time-per-tour-kpi.service';
import { TimePerTourMetricsService } from './time-per-tour-metrics.service';

@Resolver()
export class ManagerResolver {
  constructor(
    private readonly timePerTourKpiService: TimePerTourKpiService,
    private readonly timePerTourMetricService: TimePerTourMetricsService,
  ) {}

  @Query(() => [TimePerTourKPISummaryObjectType])
  toursPerTimeKPI(
    @Args('ordinanceTypes', { type: () => String }) ordinanceType: string,
  ) {
    return this.timePerTourKpiService.toursPerTimeKPI(ordinanceType);
  }

  @Query(() => [TimePerTourMetricObjectType])
  timePerTourMetricForDay(
    @Args('day', { type: () => Date }) day: Date,
    @Args('ordinanceType', { type: () => String }) ordinanceType: string,
  ) {
    return this.timePerTourMetricService.forDay(day, ordinanceType);
  }

  @Query(() => [TimePerTourMetricObjectType])
  timePerTourMetricForMonth(
    @Args('day', { type: () => Date }) day: Date,
    @Args('ordinanceType', { type: () => String }) ordinanceType: string,
  ) {
    return this.timePerTourMetricService.forMonth(day, ordinanceType);
  }

  @Subscription(() => TimePerTourUpdateObjectType)
  timePerTourUpdated() {
    return this.timePerTourKpiService.pubSub.asyncIterableIterator(
      'timePerTourUpdated',
    );
  }
}
