<?php

namespace App\Http\Controllers;
use Session;
use App\Models;
use Illuminate\Http\Request;

class ProjectStatusesController extends Controller
{
    //load up project status
    public function index(){
        $user_id = \Auth::user()->id;
        // dd($user_id);
        $result = Models\ProjectStatus::with('project')
                    ->where('assignee_id', $user_id)
                    ->orderBy('project_id', 'DESC')
                    ->get();
        $data = [
            'page_title' => 'Projects Status List',
            'project_statuses' => $result
        ];
        return view('project_status.index', $data);
    }
    public function add_status($id){
        $result = Models\Project::with('statusInfo')->where('id', $id)->firstOrFail();
        $data = [
            'page_title' => 'Projects Status Update',
            'project' => $result
        ];
        // dd($data);
        return view('project_status.add_status', $data);
    }
    public function create() {
        
        return view('project_status.create');
    }

    public function store(Request $request) {
        // Save a new post
        $this->validate($request, [
            'description' => 'required',
            'status' => 'required',
            'project_id' => 'required',
            'assignee_id' => 'required'
        ]);
        $project_status_arr = $request->except('_token');
        $result = Models\ProjectStatus::create($project_status_arr);
        Session::flash('success_message', 'Project status added successfully!');

        return redirect(url('projects'));
    }

    public function show($id) {
        // Show a specific post
    }

    public function edit($id) {
        // Show form to edit a post
    }

    public function update(Request $request, $id) {
        // Update a specific post
        return redirect(url('project-status'));
    }

    public function destroy($id) {
        // Delete a specific post
    }
}
