<?php namespace App\Http\Controllers;

use App\Auction;
use App\Bid;
use App\Http\Requests;
use App\Http\Controllers\Controller;

use App\Http\Requests\BidRequest;
use App\Product;
use Auth;
use Illuminate\Http\Request;
use Session;

/**
 * Class AuctionController
 * @package App\Http\Controllers
 */
class AuctionController extends Controller {

	/**
	 * Displays the auctions page
	 *
	 * @param Auction $auction
	 * @return \Illuminate\View\View
	 */
	public function show(Auction $auction){
		$product = $auction->product;
		return view('auctions.show', compact('auction', 'product'));
	}

	/**
	 * New bid for the auction
	 *
	 * @param Product $product
	 * @param Auction $auction
	 */
	public function bid(Product $product, Auction $auction, BidRequest $request){
		$bid = new Bid($request->all());
		$bid->user_id = Auth::user()->id;
		$auction->bids()->save($bid);
		Session::flash('flash_message', 'Bid accepted');
		return redirect()->back();
	}

}
