class ProgramRepository {
  constructor(prisma) { this.prisma = prisma; }

  listAll({ search, activeOnly = false } = {}) {
    const where = {};
    if (search) where.name = { contains: search };
    if (activeOnly) where.isActive = true;
    return this.prisma.program.findMany({
      where,
      orderBy: { createdAt: 'desc' },
    });
  }

  findById(id) {
    return this.prisma.program.findUnique({ where: { id } });
  }

  findByCode(code) {
    return this.prisma.program.findUnique({ where: { code } });
  }

  create(data) {
    return this.prisma.program.create({ data });
  }

  update(id, data) {
    return this.prisma.program.update({ where: { id }, data });
  }

  delete(id) {
    return this.prisma.program.delete({ where: { id } });
  }

  count() {
    return this.prisma.program.count();
  }
}

export default ProgramRepository;
