import {
  Body,
  Controller,
  Delete,
  Param,
  Patch,
  Post,
  Put,
} from '@nestjs/common';
import { FaqDataOrchestrator } from '../domain/usecases/faq-data.orchestrator';
import { FaqDto } from './dto/faq.dto';
import { MODULE_NAME } from 'src/core/strings/constants/module.constants';
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
import { FaqEntity } from '../domain/entities/faq.entity';
import { BatchResult } from 'src/core/response/domain/ok-response.interface';
import { BatchIdsDto } from 'src/core/modules/infrastructure/dto/base-batch.dto';
import { Public } from 'src/core/guards';
import { ChangePositionDto } from 'src/core/modules/infrastructure/dto/base-change-position.dto';

@ApiTags(`${MODULE_NAME.FAQ.split('-').join(' ')} - data`)
@Controller(`v1/${MODULE_NAME.FAQ}`)
@Public(false)
@ApiBearerAuth('JWT')
export class FaqDataController {
  constructor(private orchestrator: FaqDataOrchestrator) {}

  @Post()
  async create(@Body() data: FaqDto): Promise<FaqEntity> {
    return await this.orchestrator.create(data);
  }

  @Post('/change-position')
  async dragDrop(@Body() body: ChangePositionDto): Promise<string> {
    return await this.orchestrator.changePostion(body);
  }

  @Put('/batch-delete')
  async batchDeleted(@Body() body: BatchIdsDto): Promise<BatchResult> {
    return await this.orchestrator.batchDelete(body.ids);
  }

  @Patch(':id/active')
  async active(@Param('id') dataId: string): Promise<string> {
    return await this.orchestrator.active(dataId);
  }

  @Put('/batch-active')
  async batchActive(@Body() body: BatchIdsDto): Promise<BatchResult> {
    return await this.orchestrator.batchActive(body.ids);
  }

  @Patch(':id/confirm')
  async confirm(@Param('id') dataId: string): Promise<string> {
    return await this.orchestrator.confirm(dataId);
  }

  @Put('/batch-confirm')
  async batchConfirm(@Body() body: BatchIdsDto): Promise<BatchResult> {
    return await this.orchestrator.batchConfirm(body.ids);
  }

  @Patch(':id/inactive')
  async inactive(@Param('id') dataId: string): Promise<string> {
    return await this.orchestrator.inactive(dataId);
  }

  @Put('/batch-inactive')
  async batchInactive(@Body() body: BatchIdsDto): Promise<BatchResult> {
    return await this.orchestrator.batchInactive(body.ids);
  }

  @Put(':id')
  async update(
    @Param('id') dataId: string,
    @Body() data: FaqDto,
  ): Promise<FaqEntity> {
    return await this.orchestrator.update(dataId, data);
  }

  @Delete(':id')
  async delete(@Param('id') dataId: string): Promise<string> {
    return await this.orchestrator.delete(dataId);
  }
}
