<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Models\SupportTicket;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Validation\Rule;
use Illuminate\View\View;

/**
 * Platform-wide inbox for tickets raised via Admin\HelpController — Super
 * Admin only, since a ticket can come from any company and isn't scoped to
 * one tenant's own staff to manage.
 */
class SupportTicketController extends Controller
{
    public function index(): View
    {
        return view('admin.support-tickets.index', [
            'tickets' => SupportTicket::with(['company', 'user'])->latest()->get(),
        ]);
    }

    public function updateStatus(Request $request, SupportTicket $supportTicket): RedirectResponse
    {
        $data = $request->validate([
            'status' => ['required', Rule::in(['open', 'resolved'])],
        ]);

        $supportTicket->update($data);

        return back()->with('success', 'Ticket status updated.');
    }
}
