<?php

namespace App\Http\Controllers;

use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Inertia\Inertia;
use Inertia\Response;

class LandingController extends Controller
{
    public function home(): Response
    {
        return Inertia::render('Landing/Home', [
            'title' => 'دانشیار من',
        ]);
    }

    public function pricing(): Response
    {
        return Inertia::render('Landing/Pricing');
    }

    public function faq(): Response
    {
        return Inertia::render('Landing/Faq');
    }

    public function contact(): Response
    {
        return Inertia::render('Landing/Contact');
    }

    public function storeContact(Request $request): RedirectResponse
    {
        $data = $request->validate([
            'school_name' => ['required', 'string', 'max:200'],
            'manager_name' => ['required', 'string', 'max:200'],
            'mobile' => ['required', 'string', 'max:20'],
            'city' => ['nullable', 'string', 'max:120'],
            'message' => ['nullable', 'string', 'max:1000'],
        ]);

        DB::table('contact_requests')->insert([
            'school_name' => $data['school_name'],
            'manager_name' => $data['manager_name'],
            'mobile' => $data['mobile'],
            'city' => $data['city'] ?? null,
            'message' => $data['message'] ?? null,
            'ip_address' => $request->ip(),
            'created_at' => now(),
            'updated_at' => now(),
        ]);

        return redirect()->back()->with('success', 'درخواست شما ثبت شد.');
    }
}
