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

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

  // Return active master options for a group (e.g. type = "status"),
  // ordered for display.
  async findByType(type: string) {
    const where: any = { isActive: true };
    if (type && type.trim() !== '') {
      where.type = type.trim();
    }

    return this.prisma.masters.findMany({
      where,
      orderBy: [{ sortOrder: 'asc' }, { label: 'asc' }],
      select: { id: true, type: true, value: true, label: true },
    });
  }
}
