<?php

namespace App\Http\Controllers;

use Illuminate\Support\Facades\Auth;
use Illuminate\Http\Request;
use App\Models\EdarateShahri;
//use Illuminate\Http\Request;

class HomeContentController extends Controller
{
    public function getAllProvinces(Request $request)
    {
        $provinces = \App\Models\Province::all();

        if ($request->has("self")) {
            if (!(Auth::user()->hasRole('superadmin') || Auth::user()->hasRole('management') || Auth::user()->hasRole('setadi'))) {
                $provinces = \App\Models\Province::where('id', Auth::user()->province_id)->get();
            } 
        }

        return response()->json([
            'status' => 'succeed',
            'message' => '',
            'data' => $provinces
        ], 200);
    }

    public function getAllEdarateShahri(\App\Models\City $city)
    {
        $edarate_shahri = $city->edarateShahri()->get();

        return response()->json([
            'status' => 'succeed',
            'message' => '',
            'data' => $edarate_shahri
        ], 200);
    }


    public function getAllEdarateShahriByProvince(\App\Models\Province $province)
    {
        $edarate_shahri = EdarateShahri::where('province_id', $province->id)->get();

        return response()->json([
            'status' => 'succeed',
            'message' => '',
            'data' => $edarate_shahri
        ], 200);
    }



    public function getAllEdarateOstani(Request $request)
    {
        $edarate_shahri = \App\Models\EdarateOstani::all();

        return response()->json([
            'status' => 'succeed',
            'message' => '',
            'data' => $edarate_shahri
        ], 200);
    }

    public function getAllCitiesByProvince($id)
    {
        $cities = \App\Models\City::where('province_id', $id)->where('type_id', 1)->get();
        // $cities = \App\Models\City::where('province_id', $id)->get();

        return response()->json([
            'status' => 'succeed',
            'message' => '',
            'data' => $cities
        ], 200);
    }
}
