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

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

  list(query?: string) {
    return this.prisma.samuday.findMany({
      where: {
        isActive: true,
        ...(query ? { name: { contains: query } } : {}),
      },
      orderBy: [{ displayOrder: 'asc' }, { name: 'asc' }],
      select: { samudayId: true, name: true },
    });
  }

  create(name: string) {
    return this.prisma.samuday.create({
      data: { name: name.trim() },
      select: { samudayId: true, name: true },
    });
  }
}
