<?php

namespace App\Http\Controllers;

use App\Models\NewsletterSubscriber;
use Illuminate\Http\Request;

class NewsletterController extends Controller
{
    public function store(Request $request)
    {
        $request->validate([
            'email' => 'required|email|max:255',
        ]);

        NewsletterSubscriber::firstOrCreate(
            ['email' => $request->input('email')],
            [
                'ip_address'   => $request->ip(),
                'is_active'    => true,
                'confirmed_at' => now(),
            ]
        );

        return back()->with('success', 'Thank you for subscribing!');
    }
}
