<?php

namespace App\Http\Controllers\User;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class PartnerAgreementController extends Controller
{
    public function index()
    {
        $user = Auth::user();
 
        return view('app.main.partner-agreement', [
            'user' => $user,
            'date' => now()->format('M d Y'),
        ]);
    }

    public function store(Request $request)
    {
        try {
            $request->validate([
                'signature' => 'required|string|max:255',
            ]);

            $user = Auth::user();
            $user->partner_signature = $request->signature;
            $user->partner_signed_at = now();
            $user->save();

            return back()->with('success', 'Agreement signed successfully.');
        } catch (\Exception $e) {
            return back()->with('error', 'Something went wrong: ' . $e->getMessage());
        }
    }
}
