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

export interface Plan {
  id: string;
  name: string;
  description: string;
  monthlyPrice: number;
  yearlyPrice: number;
  features: string[];
  popular?: boolean;
}

@Injectable()
export class PlansService {
  private plans: Plan[] = [
    {
      id: 'starter',
      name: 'Starter',
      description: 'For small companies',
      monthlyPrice: 99,
      yearlyPrice: 990,
      features: ['5 job postings', 'Basic analytics', 'Email support'],
    },
    {
      id: 'professional',
      name: 'Professional',
      description: 'For growing companies',
      monthlyPrice: 299,
      yearlyPrice: 2990,
      popular: true,
      features: [
        '25 job postings',
        'Advanced analytics',
        'Priority support',
        'Featured listings',
      ],
    },
    {
      id: 'enterprise',
      name: 'Enterprise',
      description: 'For large organizations',
      monthlyPrice: 799,
      yearlyPrice: 7990,
      features: [
        'Unlimited postings',
        'Custom analytics',
        'Dedicated support',
        'API access',
      ],
    },
  ];

  getAllPlans(): Plan[] {
    return this.plans;
  }

  getPlanById(id: string): Plan | undefined {
    return this.plans.find((p) => p.id === id);
  }

  createPlan(plan: Plan): Plan {
    this.plans.push(plan);
    return plan;
  }

  updatePlan(id: string, updates: Partial<Plan>): Plan | undefined {
    const index = this.plans.findIndex((p) => p.id === id);
    if (index === -1) {
      return undefined;
    }
    this.plans[index] = { ...this.plans[index], ...updates };
    return this.plans[index];
  }

  deletePlan(id: string): boolean {
    const index = this.plans.findIndex((p) => p.id === id);
    if (index === -1) {
      return false;
    }
    this.plans.splice(index, 1);
    return true;
  }
}

