import { Injectable } from '@nestjs/common';
import { PrismaService } from '../prisma/prisma.service';

@Injectable()
export class GalleryService {
  constructor(private prisma: PrismaService) {}

  async findAllPhotos() {
    return this.prisma.galleryPhoto.findMany({ orderBy: { createdAt: 'desc' } });
  }

  async findAllVideos() {
    return this.prisma.galleryVideo.findMany({ orderBy: { createdAt: 'desc' } });
  }

  async createPhoto(data: { title?: string; image: string }) {
    return this.prisma.galleryPhoto.create({ data });
  }

  async createVideo(data: { title?: string; youtubeUrl: string }) {
    return this.prisma.galleryVideo.create({ data });
  }

  async updatePhoto(id: number, data: { title?: string; image?: string }) {
    return this.prisma.galleryPhoto.update({ where: { id }, data });
  }

  async updateVideo(id: number, data: { title?: string; youtubeUrl?: string }) {
    return this.prisma.galleryVideo.update({ where: { id }, data });
  }

  async deletePhoto(id: number) {
    return this.prisma.galleryPhoto.delete({ where: { id } });
  }

  async deleteVideo(id: number) {
    return this.prisma.galleryVideo.delete({ where: { id } });
  }
}
