<?php

namespace App\Http\Controllers\Api;

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

class UserDataController extends Controller
{

    public function getUserProvince()
    {
        if (Auth::user()->hasRole('superadmin')|| Auth::user()->hasRole('management') || Auth::user()->hasRole('setadi')) {
            // $data = Province::orderBy('id','desc')->get();
            $data = Province::all();
        } else {
            $data = Province::where('id', Auth::user()->province_id)->get();
        }
        return response()->json([
            'message' => 'success',
            'data' => [
                'province_id' => $data
            ]
        ]);
    }

    public function getUserProvinceAfterPermission(Request $request)
    {
        if ($request->type == 'all') {
            $data = Province::all();
        } else {
            $data = Province::where('id', Auth::user()->province_id)->get();
        }
        return response()->json([
            'message' => 'success',
            'data' => $data
        ]);
    }

}