import { AuthMethod, MultiTenancyInterceptor, UseAuth } from '@backend/auth'
import { Controller, Get, UseInterceptors } from '@nestjs/common'
import { ApiBadRequestResponse, ApiInternalServerErrorResponse, ApiOkResponse, ApiTags } from '@nestjs/swagger'
import { DashboardService } from './dashboard.service'
import { DashboardMessageView, DashboardTableView } from './types'

@UseAuth(AuthMethod.JWT)
@UseInterceptors(MultiTenancyInterceptor)
@Controller('dashboard')
@ApiTags('default')
export class DashboardController {
	constructor(private readonly _dashboardService: DashboardService) {}

	@Get('table')
	@ApiOkResponse({ type: DashboardTableView, isArray: true })
	@ApiBadRequestResponse({ description: 'Bad request' })
	@ApiInternalServerErrorResponse({ description: 'Internal server error' })
	async getTablesView(): Promise<DashboardTableView[]> {
		return this._dashboardService.getTablesView()
	}

	@Get('message')
	@ApiOkResponse({ type: DashboardMessageView, isArray: true })
	@ApiBadRequestResponse({ description: 'Bad request' })
	@ApiInternalServerErrorResponse({ description: 'Internal server error' })
	async getMessagesView(): Promise<DashboardMessageView[]> {
		return this._dashboardService.getMessagesView()
	}
}
