<?php

namespace App\Http\Controllers\API\v1;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class GeoController extends Controller
{
    public function getRegions()
    {
        $regions = DB::table('region')->get();

        return response()->json($regions);
    }

    public function getProvinces($regionId)
    {
        $provinces = DB::table('province')
            ->where('regCode', $regionId)
            ->get();

        return response()->json($provinces);
    }

    public function getCities($provinceId)
    {
        $cities = DB::table('city')
            ->where('provCode', $provinceId)
            ->get();

        return response()->json($cities);
    }

    public function getBarangays($cityId)
    {
        $barangays = DB::table('barangay')
            ->where('citymunCode', $cityId)
            ->get();

        return response()->json($barangays);
    }
}
