import {
  Body,
  Controller,
  Delete,
  Get,
  Param,
  Post,
  Put,
  Res,
} from '@nestjs/common';
import { Paginate, PaginateQuery } from 'nestjs-paginate';
import { CreateBidDto } from '../../dto/bid/create-bid.dto';
import { BidsService } from '../../services/bids.service';
import { Bid } from '../../entities/bid.entity';
import { DeletesDto } from '../../dto/deletes.dto';
import { UpdateBidDto } from '../../dto/bid/update-bid.dto';
import { Response } from 'express';

@Controller('admin/bids')
export class AdminBidsController {
  constructor(private readonly bidsService: BidsService) {}

  @Get()
  async index(@Paginate() query: PaginateQuery) {
    return await this.bidsService.index(query);
  }

  @Post()
  create(@Body() data: CreateBidDto) {
    return this.bidsService.create(data);
  }

  @Put(':id')
  update(@Param('id') id: Bid['id'], @Body() data: UpdateBidDto) {
    return this.bidsService.update(id, data);
  }

  @Delete(':id')
  async delete(@Param('id') id: Bid['id']) {
    return await this.bidsService.delete(id);
  }

  @Post('deletes')
  async deletes(@Body() data: DeletesDto) {
    return await this.bidsService.deletes(data.ids);
  }

  @Post('toggle/:id')
  toggle(@Param('id') id: Bid['id']) {
    return this.bidsService.toggle(id);
  }

  @Get('status-working/:type/:id/:name')
  async getStatusWorkingImage(
    @Param('id') id: Bid['id'],
    @Param('type') type: string,
    @Param('name') name: string,
    @Res() res: Response,
  ) {
    return await this.bidsService.getStatusWorkingImage(id, type, name, res);
  }

  @Get('images-working/:type/:id')
  async getImagesWorking(
    @Param('id') id: Bid['id'],
    @Param('type') type: string,
  ) {
    return await this.bidsService.getImagesWorking(id, type);
  }

  @Get('record/:name')
  async getRecord(@Param('name') name: string, @Res() res: Response) {
    return await this.bidsService.getRecord(name, res);
  }

  @Get('records/:id')
  async getRecords(@Param('id') id: Bid['id']) {
    return await this.bidsService.getRecords(id);
  }

  @Delete('record/:name')
  async deleteRecord(@Param('name') name: string) {
    return await this.bidsService.deleteRecord(name);
  }
}
