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

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

  async findOne(id: string) {
    const tenant = await this.prisma.tenant.findUnique({
      where: { id },
      include: { _count: { select: { users: true, clients: true, orders: true } } },
    });
    if (!tenant) throw new NotFoundException('Empresa não encontrada');
    return tenant;
  }

  async updateSettings(id: string, data: { name?: string; logoUrl?: string; primaryColor?: string }) {
    return this.prisma.tenant.update({ where: { id }, data });
  }
}
