import { prisma } from '../../../infra/database/prisma'
import type { InstanceStatus } from '@prisma/client'

export class InstanceRepository {
  async findAllByTenant(tenantId: string) {
    return prisma.instance.findMany({
      where: { tenantId },
      orderBy: { createdAt: 'asc' },
    })
  }

  async findById(id: string) {
    return prisma.instance.findUnique({ where: { id } })
  }

  async create(tenantId: string, name: string) {
    return prisma.instance.create({
      data: { tenantId, name },
    })
  }

  async updateStatus(id: string, status: InstanceStatus) {
    return prisma.instance.update({ where: { id }, data: { status } })
  }

  async delete(id: string) {
    return prisma.instance.delete({ where: { id } })
  }
}
