<?php

namespace App\Http\Controllers;

use App\Models\ClientProfile;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class ClientProfileController extends Controller
{
    public function create()
    {
        $profile = ClientProfile::where(
            'user_id',
            Auth::id()
        )->first();

        return view(
            'client.personal-details',
            compact('profile')
        );
    }

    public function store(Request $request)
    {
        $validated = $request->validate([

            'full_name' => [
                'required',
                'string',
                'max:255',
            ],

            'date_of_birth' => [
                'required',
                'date',
            ],

            'mobile' => [
                'required',
                'string',
                'max:20',
            ],

            'address' => [
                'required',
                'string',
                'max:500',
            ],

            'city' => [
                'required',
                'string',
                'max:100',
            ],

            'state' => [
                'required',
                'string',
                'max:100',
            ],

            'pincode' => [
                'required',
                'digits:6',
            ],
        ]);


        $validated['user_id'] = Auth::id();


        ClientProfile::updateOrCreate(
            [
                'user_id' => Auth::id(),
            ],
            $validated
        );


        return redirect()->route(
            'client.kyc'
        );
    }
}