<?php

namespace App\Http\Controllers;

use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\View\View;

class CheckoutController extends Controller
{
    public function show(): View
    {
        return view('checkout');
    }

    public function submit(Request $request): RedirectResponse
    {
        $request->validate([
            'email' => 'required|email',
            'country' => 'required|string|max:2',
            'firstname' => 'required|string|max:255',
            'lastname' => 'required|string|max:255',
            'address1' => 'required|string|max:500',
            'city' => 'required|string|max:255',
            'zone' => 'required|string|max:10',
            'postalCode' => 'required|string|max:20',
            'payment_method' => 'nullable|string|in:stripe,paypal,square',
            'save_mobile' => 'nullable|string|max:32',
        ]);

        return redirect()
            ->route('shop.index')
            ->with('status', __('Thank you. Your order details were received.'));
    }
}
