<?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\View\View;

/**
 * SUP-01: a lightweight in-app help center — a searchable-by-scrolling FAQ
 * plus a contact form that raises a SupportTicket, reusing the same
 * "public form -> admin-reviewed record" shape as the marketing site's
 * Request-a-Demo / Admin\DemoRequestController.
 */
class HelpController extends Controller
{
    public function index(): View
    {
        return view('admin.help.index');
    }

    public function submitTicket(Request $request): RedirectResponse
    {
        $data = $request->validate([
            'subject' => ['required', 'string', 'max:255'],
            'message' => ['required', 'string', 'max:2000'],
        ]);

        SupportTicket::create($data + [
            'company_id' => $request->user()->company_id,
            'user_id' => $request->user()->id,
        ]);

        return back()->with('success', "Thanks — we've received your message and will get back to you shortly.");
    }
}
