<?php

namespace App\Http\Controllers\Member;

use App\Http\Controllers\Controller;
use App\Models\Plan;
use App\Services\SubscriptionService;
use Illuminate\Http\Request;

class SubscriptionController extends Controller
{
    protected $service;

    public function __construct(SubscriptionService $service)
    {
        $this->service = $service;
    }

    public function plans()
    {
        $plans = Plan::where('role_type', 'member')->where('is_active', true)->get();
        return view('member.plans.index', compact('plans'));
    }

    public function select(Plan $plan)
    {
        if ($plan->role_type !== 'member') abort(403);
        
        $this->service->createPending(auth()->user(), $plan);
        return redirect()->route('member.payment.show');
    }
}
