<?php

namespace Mehrab\City\Http\Controllers;

use App\Http\Controllers\Controller;
use Illuminate\Http\JsonResponse;
use Mehrab\City\Http\Requests\city_store_request;
use Mehrab\City\Http\Requests\city_update_request;
use Mehrab\City\Models\City;
use Mehrab\City\Repositories\CityRepo;


class CityController extends Controller
{
    private $CityRepo;

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

    public function index(){

        $this->authorize('manage',City::class);

        $Cities = $this->CityRepo->all();

        return view('City::Admin.list_city',compact('Cities'));

    }

    public function create()
    {
        $this->authorize('manage',City::class);
        return view('City::Admin.create_city');
    }

    public function store(city_store_request $request){
        $this->authorize('manage',City::class);
        $this->CityRepo->store($request);
         return redirect()->route('city.index')->with('status','created');
    }


    public function edit($cityID){
      $this->authorize('manage',City::class);
      $city = $this->CityRepo->findById($cityID);
      return view('City::Admin.edit_city',compact('city'));
    }

    public function update(city_update_request $request,$id){
        $this->authorize('manage',City::class);
        $this->CityRepo->update($request,$id);
        //return response('',200);
        return redirect()->route('city.index')->with('status','updated');
    }

    public function status($id){
        $this->authorize('manage',City::class);
        return  $this->CityRepo->status($id);
    }

    public function destroy($id){
        $this->authorize('manage',City::class);
//       return  $this->CityRepo->delete($id);
    }

}
