<?php

namespace App\Http\Controllers\Api\Front;

use App\Http\Controllers\Controller;
use App\Models\City;
use App\Models\Province;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;

class UserController extends Controller
{
    // public function profile() {
    //     return response()->json([
    //         'message' => 'success',
    //         'data' => User::where('id', Auth::user()->id)->with(['roles', 'permissions'])->get()
    //     ]);
    // }

    // public function edit(Request $request) {
    //     $user = User::find(auth()->user()->id);

    //     $validData = $request->validate([
    //         'name' => ['string'],
    //         'first_name' => ['string'],
    //         'last_name' => 'string',
    //         'position' => 'string',
    //         'mobile' => 'digits:11|regex:/^09[0-9]{9}$/i',
    //         'degree' => 'string',
    //     ]);

    //     if ($request->has('username')) {
    //         $request->validate([
    //             'username' => 'unique:users'
    //         ]);
    //         $validData['username'] = $request->username;
    //     }


    //     // Upload user avatar [For create user by Super admin is not required]
    //     if ($request->has('avatar')) {
    //         $file = $request->file('avatar');
    //         $destinationPath = 'storage/avatar/' . now()->year . '/' . now()->month . '/';
    //         // return $destinationPath;
    //         $filename = $user->username . '-updated.' . $file->getClientOriginalExtension();
    //         $file->move(public_path($destinationPath), $filename);
    //         $user->update(['avatar' => $destinationPath . $filename]);
    //     }

    //     if( $request->has('password')) {
    //         $request->validate([
    //             'password' => ['string', 'min:6']
    //         ]);

    //         $validData['password'] = Hash::make($request->password);
    //     }

    //     $user->update($validData);

    //     return response()->json([
    //         'message' => 'user is updated successfuly.',
    //         'data' => $user
    //     ]);
    // }

    // public function storeInformation(Request $request, $id) {
    //     $user = User::find($id);

    //     $validData = $request->validate([
    //         'username' => 'string|unique:users',
    //         'password' => 'min:3',
    //         'mobile' => 'digits:11|regex:/^09[0-9]{9}$/i',
    //     ]);

   

    //     $user->first_name = $request->first_name;
    //     $user->last_name = $request->last_name;
    //     $user->position = $request->position;
    //     $user->mobile = $request->mobile;
    //     $user->password = Hash::make($request->password);
    //     $user->confirmed = 1;
    //     $user->save();
        
    //     // Upload user avatar [For create user by Super admin is not required]
    //     if ($request->has('avatar')) {
    //         $file = $request->file('avatar');
    //         $destinationPath = 'storage/avatar/' . now()->year . '/' . now()->month . '/';
    //         $filename = $user->username . '-updated.' . $file->getClientOriginalExtension();
    //         $file->move(public_path($destinationPath), $filename);
    //         $user->photo = $destinationPath . $filename;
    //         $user->save();
    //     }

    //     return response()->json([
    //         'message' => 'success',
    //         'data' => $user,
    //     ]);
    // }


    // public function getMyData()
    // {
    //     $user = User::find(Auth::user()->id);

    //     return response()->json([
    //         'message' => 'success',
    //         'data' => $user
    //     ]);
    // }
}