<?php

namespace App\Http\Controllers\API;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class ProfileController extends Controller
{
    public function show(Request $request){
        return response()->json([
            "status"=>true,
            "data"=>$request->user()
        ]);
    }

    public function update(Request $request){
        $user=$request->user();

        $request->validate([
            'name'=> 'nullable|string|max:255',
            'mobile'=>'nullable|digits:10|unique:users,mobile,' . $user->id,
        ]);

        $user -> update($request->only('name','mobile'));

        return response()->json([
            'status' => true,
            'message' => 'Profile updated successfully',
            'data' => $user
        ]);

    }
}
