import { Product } from '@/entities/product.entity';
import CoreController from '@/system/core/core-controller';
import { Body, Controller, Param, Post, Sse } from '@nestjs/common';
import { ProductsService } from './products.service';
import { CreateProductDto } from './dtos/create-product.dto';
import { PublistFinishDto } from './dtos/publist-finish.dto';

@Controller('products')
export class ProductsController extends CoreController<
  Product,
  ProductsService
> {
  constructor(protected readonly service: ProductsService) {
    super(service);
  }

  @Post('')
  async create(data: CreateProductDto): Promise<any> {
    return this.service.create(data);
  }

  @Post('publist/:id')
  async publist(@Param('id') id: Product['id']): Promise<any> {
    return this.service.publist(id);
  }

  @Post('publist-finish/:id')
  async publistFinish(
    @Param('id') id: Product['id'],
    @Body() data: PublistFinishDto,
  ): Promise<any> {
    return this.service.publistFinish(id, data);
  }

  @Sse('publist-stream')
  async publistStream() {
    return this.service.sendEvents();
  }
}
