import { Controller, Get, Post, Put, Delete, Body, Param, UseGuards } from '@nestjs/common';
import { ApiTags, ApiBearerAuth } from '@nestjs/swagger';
import { GalleryService } from './gallery.service';
import { JwtAuthGuard } from '../common/guards/jwt-auth.guard';
import { RolesGuard } from '../common/guards/roles.guard';
import { Roles } from '../common/decorators/roles.decorator';

@ApiTags('Gallery')
@Controller()
export class GalleryController {
  constructor(private galleryService: GalleryService) {}

  @Get('gallery/photos')
  findAllPhotos() {
    return this.galleryService.findAllPhotos();
  }

  @Get('gallery/videos')
  findAllVideos() {
    return this.galleryService.findAllVideos();
  }

  @ApiBearerAuth()
  @UseGuards(JwtAuthGuard, RolesGuard)
  @Roles('SUPER_ADMIN', 'ADMIN')
  @Get('admin/gallery/photos')
  adminFindAllPhotos() {
    return this.galleryService.findAllPhotos();
  }

  @ApiBearerAuth()
  @UseGuards(JwtAuthGuard, RolesGuard)
  @Roles('SUPER_ADMIN', 'ADMIN')
  @Get('admin/gallery/videos')
  adminFindAllVideos() {
    return this.galleryService.findAllVideos();
  }

  @ApiBearerAuth()
  @UseGuards(JwtAuthGuard, RolesGuard)
  @Roles('SUPER_ADMIN', 'ADMIN')
  @Post('admin/gallery/photos')
  createPhoto(@Body() data: { title?: string; image: string }) {
    return this.galleryService.createPhoto(data);
  }

  @ApiBearerAuth()
  @UseGuards(JwtAuthGuard, RolesGuard)
  @Roles('SUPER_ADMIN', 'ADMIN')
  @Post('admin/gallery/videos')
  createVideo(@Body() data: { title?: string; youtubeUrl: string }) {
    return this.galleryService.createVideo(data);
  }

  @ApiBearerAuth()
  @UseGuards(JwtAuthGuard, RolesGuard)
  @Roles('SUPER_ADMIN', 'ADMIN')
  @Put('admin/gallery/photos/:id')
  updatePhoto(@Param('id') id: string, @Body() data: { title?: string; image?: string }) {
    return this.galleryService.updatePhoto(+id, data);
  }

  @ApiBearerAuth()
  @UseGuards(JwtAuthGuard, RolesGuard)
  @Roles('SUPER_ADMIN', 'ADMIN')
  @Put('admin/gallery/videos/:id')
  updateVideo(@Param('id') id: string, @Body() data: { title?: string; youtubeUrl?: string }) {
    return this.galleryService.updateVideo(+id, data);
  }

  @ApiBearerAuth()
  @UseGuards(JwtAuthGuard, RolesGuard)
  @Roles('SUPER_ADMIN', 'ADMIN')
  @Delete('admin/gallery/photos/:id')
  deletePhoto(@Param('id') id: string) {
    return this.galleryService.deletePhoto(+id);
  }

  @ApiBearerAuth()
  @UseGuards(JwtAuthGuard, RolesGuard)
  @Roles('SUPER_ADMIN', 'ADMIN')
  @Delete('admin/gallery/videos/:id')
  deleteVideo(@Param('id') id: string) {
    return this.galleryService.deleteVideo(+id);
  }
}
