import {
  Body,
  Controller,
  Delete,
  Param,
  Patch,
  Post,
  Put,
} from '@nestjs/common';
import { ApiTags, ApiBearerAuth } from '@nestjs/swagger';
import { Public } from 'src/core/guards';
import { BatchIdsDto } from 'src/core/modules/infrastructure/dto/base-batch.dto';
import { BatchResult } from 'src/core/response/domain/ok-response.interface';
import { MODULE_NAME } from 'src/core/strings/constants/module.constants';
import { ItemEntity } from 'src/modules/item-related/item/domain/entities/item.entity';
import { ItemDataOrchestrator } from 'src/modules/item-related/item/domain/usecases/item-data.orchestrator';
import { ItemDto } from 'src/modules/item-related/item/infrastructure/dto/item.dto';

@ApiTags(`${MODULE_NAME.TENANT.split('-').join(' ')} item - data`)
@Controller(`v1/${MODULE_NAME.TENANT}/:tenant_id/item`)
@Public(false)
@ApiBearerAuth('JWT')
export class TenantItemDataController {
  constructor(private orchestrator: ItemDataOrchestrator) {}

  @Post()
  async create(
    @Param('tenant_id') tenant_id: string,
    @Body() data: ItemDto,
  ): Promise<ItemEntity> {
    return await this.orchestrator.create(data, tenant_id);
  }

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

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

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

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

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

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

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

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

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