<?php

namespace App\Http\Controllers;

use App\Mail\ContactSubmissionMail;
use App\Models\ContactSubmission;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Mail;

class ContactController extends Controller
{
    public function index()
    {
        return view('contact.index');
    }

    public function store(Request $request)
    {
        $validated = $request->validate([
            'full_name' => 'required|string|max:255',
            'email'     => 'required|email|max:255',
            'phone'     => 'nullable|string|max:30',
            'message'   => 'required|string|max:5000',
        ]);

        $submission = ContactSubmission::create($validated);

        Mail::to(env('INFO_EMAIL', 'info@trollmasters.ai'))
            ->send(new ContactSubmissionMail($submission));

        return back()->with('success', 'Your message has been sent. We will get back to you shortly!');
    }
}
