<?php

namespace App\Http\Controllers\api\v1\User;

use App\Http\Controllers\Controller;
use App\Http\Requests\User\Account\AddBankRequest;
use App\Http\Requests\User\Account\ChangePasswordRequest;
use App\Http\Requests\User\Account\SetPinRequest;
use App\Http\Requests\User\Account\UpdateProfileRequest;
use App\Http\Requests\User\Account\VerifyBvnOtpRequest;
use App\Http\Requests\User\Account\VerifyBvnRequest;
use App\Service\User\UserService;
use App\Traits\JsonResponseTrait;
use Illuminate\Http\Request;

class UserController extends Controller
{
    use JsonResponseTrait;
    public function __construct(protected UserService $userService) {}

    /**
     * Get the authenticated user's profile details.
     *
     * @return JsonResponseTrait
     */
    public function getProfileDetails(Request $request)
    {
        // Get the authenticated user from the middleware
        $authUser = $request->auth_user;
        return $this->userService->getProfileDetails($authUser);
    }

    /**
     * Change the authenticated user's password.
     *
     * @param  ChangePasswordRequest  $request
     * @return JsonResponse
     */
    public function changePassword(ChangePasswordRequest $request)
    {
        $authUser = $request->auth_user;
        $input = $request->validated();
        $result = $this->userService->changePassword($authUser, $input['current_password'], $input['new_password']);

        return $result;
    }


   

    /**
     * Update the authenticated user's profile.
     *
     * @param  UpdateProfileRequest  $request
     * @return JsonResponse
     */
    public function updateProfile(UpdateProfileRequest $request)
    {
        $authUser = $request->auth_user;
        $input = $request->validated();
        return $this->userService->updateProfile($authUser, $input);
    }

    /**
     * Set a new PIN for the authenticated user.
     *
     * @param  SetPinRequest  $request
     * @return JsonResponse
     */
    public function setPin(SetPinRequest $request)
    {
        $authUser = $request->auth_user;
        $input = $request->validated();
        $result = $this->userService->setPin($authUser, $input['pin']);
        return $result;
    }
    public function changePin(SetPinRequest $request)
    {
        $authUser = $request->auth_user;
        $input = $request->validated();
        $result = $this->userService->setPin($authUser, $input['pin']);
        return $result;
    }

    public function verifyBvn(VerifyBvnRequest $request)
    {
        $authUser = $request->auth_user;
        $input = $request->validated();
        $result = $this->userService->verifyBVN($authUser, $input['bvn']);
        return $result;
    }

    public function verifyBvnOtp(VerifyBvnOtpRequest $request)
    {
        $authUser = $request->auth_user;
        $input = $request->validated();
        $result = $this->userService->verifyBvnOtp($authUser, $input['otp']);
        return $result;
    }

    public function addBank (AddBankRequest $request)
    {
        $authUser = $request->auth_user;
        $input = $request->validated();
        $result = $this->userService->addBank($authUser, $input['account_no'], $input['bank_id']);
        return $result;
    }
}