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';
import { SyncDto } from './dtos/syncs.dto';

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

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

  @Post('sync')
  async sync(@Body() data: SyncDto): Promise<any> {
    return this.service.sync(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);
  }
  @Post('delete-finish/:id')
  async deleteFinish(
    @Param('id') id: Product['id'],
    @Body() data: PublistFinishDto,
  ): Promise<any> {
    return this.service.deleteFinish(id, data);
  }

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

  @Sse('delete-stream')
  async deleteStream() {
    return this.service.sendDeleteEvents();
  }
}
