<?php

namespace App\Http\Controllers\Admin;

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

class PackageController extends Controller
{
    public function index()
    {
        $packages = Plan::all();
        return view('admin.packages.index', compact('packages'));
    }

    public function create()
    {
        return view('admin.packages.create');
    }

    public function store(Request $request)
    {
        $request->validate([
            'name' => 'required',
            'role_type' => 'required',
            'price' => 'required|numeric',
            'duration_days' => 'required|integer',
        ]);

        Plan::create([
            'name' => $request->name,
            'role_type' => $request->role_type,
            'price' => $request->price,
            'duration_days' => $request->duration_days,
            'features_json' => explode(',', $request->features),
            'is_active' => true,
        ]);

        return redirect()->route('admin.packages.index')->with('success', 'Paket berhasil dibuat.');
    }
}
