<?php

namespace App\Http\Controllers\HeadquartersDashboard;

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

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

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

        $url = $province_ip . "?" . http_build_query($payload);

        return redirect($url);
    }
}
