import { Injectable } from '@nestjs/common';
import { CreateMeetingDto } from './dto/create-meeting.dto';
import { UpdateMeetingDto } from './dto/update-meeting.dto';
import { PrismaService } from '../prisma/prisma.service';

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

  create(createMeetingDto: CreateMeetingDto) {
    return this.prisma.meeting.create({
      data: {
        ...createMeetingDto,
        date: new Date(createMeetingDto.date)
      }
    });
  }

  findAll() {
    return this.prisma.meeting.findMany({
      include: { client: true, user: true }
    });
  }

  findOne(id: string) {
    return this.prisma.meeting.findUnique({
      where: { id },
      include: { client: true, user: true }
    });
  }

  update(id: string, updateMeetingDto: UpdateMeetingDto) {
    const data: any = { ...updateMeetingDto };
    if (updateMeetingDto.date) {
      data.date = new Date(updateMeetingDto.date);
    }
    return this.prisma.meeting.update({
      where: { id },
      data: data
    });
  }

  remove(id: string) {
    return this.prisma.meeting.delete({ where: { id } });
  }
}
