import prisma from '../utils/db';

export class OrganizationService {
  public async create(data: { name: string }) {
    return await prisma.organization.create({ data });
  }

  public async getAll() {
    return await prisma.organization.findMany({
      include: {
        users: {
          select: {
            id: true,
            email: true,
            role: true,
          }
        },
        _count: {
          select: { users: true }
        }
      },
      orderBy: { createdAt: 'desc' }
    });
  }

  public async getById(id: string) {
    return await prisma.organization.findUnique({
      where: { id },
      include: { users: true }
    });
  }

  public async update(id: string, data: { name?: string, status?: string }) {
    return await prisma.organization.update({
      where: { id },
      data
    });
  }
}
