<?php

namespace App\Http\Controllers\HeadquartersDashboard;

use App\Http\Controllers\Controller;
use app\Http\Traits\ApiResponse;
use App\Models\Province;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;

class LoginToProvinceController extends Controller
{
    use ApiResponse;

    public function authenticate(Request $request)
    {
        $province_ip = Province::query()
            ->Where('id', '=', $request->province_id)
            ->value('ip_address');

        $data = [
            'user_id' => auth()->user()->id,
            'token' => Hash::make(config('globalVariables.LOGIN_HASH_VALUE')),
            'ip' => $province_ip,
        ];

        return $this->successResponse($data);
    }
}
