import { Injectable } from '@nestjs/common';

import { PrismaService } from '../prisma/prisma.service';

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

  async listActivePlans() {
    const plans = await this.prisma.plan.findMany({
      where: { isActive: true },
      orderBy: { maxRamMb: 'asc' },
    });

    return {
      plans: plans.map((plan) => ({
        id: plan.id,
        name: plan.name,
        slug: plan.slug,
        description: plan.description,
        isFree: plan.isFree,
        maxRamMb: plan.maxRamMb,
        maxCpuCores: plan.maxCpuCores,
        maxStorageMb: plan.maxStorageMb,
      })),
    };
  }
}
