<?php

namespace Mehrab\Region\Http\Controllers;

use App\Http\Controllers\Controller;
use Mehrab\City\Repositories\CityRepo;
use Mehrab\Region\Http\Requests\region_store_request;
use Mehrab\Region\Http\Requests\region_update_request;
use Mehrab\Region\Repositories\RegionRepo;


class RegionController extends Controller
{
    private $RegionRepo;

    public function __construct(RegionRepo $cityRepo)
    {
        $this->RegionRepo = $cityRepo;
    }

    public function index(){

        $Regions = $this->RegionRepo->all();

        return view('Region::Admin.list_region',compact('Regions'));

    }

    public function create(CityRepo $cityRepo)
    {
        $cities = $cityRepo->all();
        return view('Region::Admin.create_region',compact('cities'));
    }

    public function store(region_store_request $request,CityRepo $cityRepo){
            $this->RegionRepo->store($request,$cityRepo);
         return redirect()->back()->with('status','created');
    }


    public function edit($cityID,CityRepo $cityRepo){

      $region = $this->RegionRepo->findById_with_City($cityID);
      $cities = $cityRepo->all();
      return view('Region::Admin.edit_region',compact('region','cities'));
    }

    public function update(region_update_request $request,$id){
        $this->RegionRepo->update($request,$id);
        return redirect()->route('region.index')->with('status','updated');
    }

    public function status($id){
      return  $this->RegionRepo->status($id);
    }

    public function destroy($id){
//       return  $this->RegionRepo->delete($id);
    }

}
