import { Body, Controller, Get, Param, Post } from '@nestjs/common';

import { MODULE_NAME } from 'src/core/strings/constants/module.constants';
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';

import { Public } from 'src/core/guards';
import { QueueOrchestrator } from '../../domain/queue.orchestrator';
import { QueueOrder } from '../../domain/entities/order.entity';
import { Queue } from '../../domain/entities/queue.entity';
import { RegisterQueueDto } from './dto/register-queue.dto';
import { SplitQueueDto } from './dto/split-queue.dto';

@ApiTags(`Queue`)
@Controller(`v1/${MODULE_NAME.QUEUE}`)
@Public(true)
@ApiBearerAuth('JWT')
export class QueueController {
  constructor(private orchestrator: QueueOrchestrator) {}

  @Post('register')
  async registerQueue(@Body() data: RegisterQueueDto): Promise<Queue> {
    return await this.orchestrator.create(data);
  }

  @Post('split')
  async splitQueue(@Body() data: SplitQueueDto): Promise<QueueOrder> {
    return await this.orchestrator.split(data);
  }

  @Get('login/:id')
  async loginCustomer(@Param('id') id: string): Promise<QueueOrder> {
    return await this.orchestrator.loginCustomer(id);
  }

  @Get(':id/tickets')
  async queueTickets(@Param('id') id: string): Promise<void> {
    return await this.orchestrator.queueTickets(id);
  }

  @Get(':id/tickets/:ticket_id/items')
  async queueTicketItems(
    @Param('id') id: string,
    @Param('ticket_id') ticket_id: string,
  ): Promise<void> {
    return await this.orchestrator.queueTicketDetail(id, ticket_id);
  }

  @Get(':id/items')
  async queueItems(@Param('id') id: string): Promise<void> {
    return await this.orchestrator.queueItems(id);
  }

  @Get(':id/queue')
  async queueOrderItems(@Param('id') id: string): Promise<void> {
    return await this.orchestrator.queueOrderItems(id);
  }

  @Get(':id/items/:item_id')
  async queueItemTickets(
    @Param('id') id: string,
    @Param('item_id') item_id: string,
  ): Promise<void> {
    return await this.orchestrator.queueItemDetail(id, item_id);
  }
}
