<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Http\Requests\GoalRequest;
use App\Models\Goal;
use Illuminate\Http\Request;

class GoalsController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        return view('admin.goals.index', [ 
            'goals' => Goal::all(), 
        ]);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        return view('admin.goals.create');
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \App\Http\Requests\GoalRequest  $request
     * @return \Illuminate\Http\Response
     */
    public function store(GoalRequest $request)
    {
        Goal::create($request->getGoalPayload());

        return redirect()->route('goals.index');
    }

    /**
     * Display the specified resource.
     *
     * @param  \App\Model\Goal  $goal
     * @return \Illuminate\Http\Response
     */
    public function show(Goal $goal)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  \App\Model\Goal  $goal
     * @return \Illuminate\Http\Response
     */
    public function edit(Goal $goal)
    {
        return view('admin.goals.edit', [
            'goal' => $goal,
        ]);
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \App\Http\Requests\GoalRequest  $request
     * @param  \App\Model\Goal  $goal
     * @return \Illuminate\Http\Response
     */
    public function update(GoalRequest $request, Goal $goal)
    {
        $goal->update($request->getGoalPayload());

        return redirect()->route('goals.index');
    }

    public function enabled(Goal $goal)
    {
        $goal->update(['enabled' => !$goal->enabled]);

        return redirect()->route('goals.index');
    }
    
    /**
     * Remove the specified resource from storage.
     *
     * @param  \App\Model\Goal  $goal
     * @return \Illuminate\Http\Response
     */
    public function destroy(Goal $goal)
    {
        //
    }
}
