<?php

namespace App\Http\Controllers;

use App\Domain\Website\Services\WebsiteDataService;
use Illuminate\Http\Request;

class ContactFormController extends Controller
{
    public function submit(Request $request, string $slug)
    {
        $validated = $request->validate([
            'name' => 'required|string|max:255',
            'phone' => 'required|string|max:20',
            'email' => 'nullable|email|max:255',
            'message' => 'required|string|max:2000',
        ]);

        $academy = app('current_academy');

        app(WebsiteDataService::class)->submitContactForm($academy, $validated);

        if ($request->expectsJson()) {
            return response()->json(['message' => 'تم إرسال رسالتك بنجاح']);
        }

        return back()->with('contact_success', 'تم إرسال رسالتك بنجاح، سنتواصل معك قريباً');
    }
}
