<?php

class UserserviceController extends \BaseController {
	
	var $dummyusername = "r@v.com";
	var $dummyuserid = 2511;
	/**
     * Instantiate a new UserserviceController instance.
     */
    public function __construct()
    {
        $this->beforeFilter(function()
        {
            header('Access-Control-Allow-Origin: *');
        });
    }

	
	public function getLogin(){
		return ["status"=>"Still not OK via GET"];
	}
	
	public function postLogin()
	{
		//return ["status"=>"Still not OK via POST"];
		$rdata = [
			"c2dictionary" => true,
			"data" => [
				"status" => "error",
				"statusMessage" => "Error occoured. Username not found"
			]
		];

		if(Input::has("username") && Input::has("password") && Input::get("username") == $this->dummyusername){
			$rdata["data"]["status"] = "success";
			$rdata["data"]["statusMessage"] = "Logged in Successfully";
			$rdata["data"]["user"] = [
				"username"=>"r@v.com",
				"name"=>"Ravi Shekhar",
				"userid" => $this->dummyuserid
			];
			
		}
		//return ["status"=>"Still not OK via POST"];
		return $rdata;
	}

	/**
	 * Show the form for creating a new resource.
	 *
	 * @return Response
	 */
	public function postGames()
	{
		if(Input::has("userid") && Input::get("userid") == $this->dummyuserid){
			return [
				[
					"id"=>"1",
					"name"=>"Mind Your Head",
					"enabled"=>true,
					"price"=>"1.09",
					"bought"=>true
				],
				[
					"id"=>"2",
					"name"=>"Attack The Block",
					"enabled"=>true,
					"price"=>"1.09",
					"bought"=>true
				],
				[
					"id"=>"3",
					"name"=>"Save The Cell",
					"enabled"=>true,
					"price"=>"1.09",
					"bought"=>false
				],
				[
					"id"=>"4",
					"name"=>"Shop Till You Drop",
					"enabled"=>true,
					"price"=>"1.09",
					"bought"=>true
				],
				[
					"id"=>"5",
					"name"=>"Coming Soon",
					"enabled"=>false,
					"price"=>"1.09",
					"bought"=>false
				],
				[
					"id"=>"6",
					"name"=>"Coming Soon",
					"enabled"=>false,
					"price"=>"1.09",
					"bought"=>false
				],
			];
		}
		return [];
	}

	public function postMyprofile()
	{
		$rdata = [
			"status" => "failure",
			"statusMessage" => "User profile not found for this ID"
		];
		
		if ( Input::has("userid") && Input::get("userid") == $this->dummyuserid ){
			$rdata["status"] = "success";
			
			$rdata["data"] = [			
				"userid" => "58",
				"username" => "dipanshu",
				"email" => "dipanshu@qsstechnosoft.com",
				"bio" => "This is a bio for user dipanshu",
				"status" => [
					[
						"status_id" => "1",
						"reply" => "0",
						"email" => "",
						"userid" => "58",
						"status" => "Feeling Happy and get well soon!!!",
						"createdDate" => "2014-03-13 07:06:01"
					],
					[
						"status_id" => "2",
						"reply" => "0",
						"email" => "",
						"userid" => "58",
						"status" => "'Silence is a source of great strength.' - Lao Tsu",
						"createdDate" => "2014-03-13 07:06:01"
					],
					[
						"status_id" => "3",
						"reply" => "0",
						"email" => "",
						"userid" => "58",
						"status" => "If you have the power to make someone happy, do it. The world needs more of that. That's what my tweets are for. RT if you love it. Love u.",
						"createdDate" => "2014-03-13 07:06:01"
					]
				],
				"followers" => 10,
				"following" => 20
			];
			
		}
		return $rdata;
	}


	public function postTimeline()
	{
		$rdata = [
			"status" => "failure",
			"statusMessage" => "User timeline not found for this ID"
		];
		
		if ( Input::has("userid") && Input::get("userid") == $this->dummyuserid ){
			$rdata["status"] = "success";
			
			$rdata["data"] = [			
				"notifications" => 12,
				"status" => [
					[
						"status_id" => "1",
						"reply" => "0",
						"email" => "",
						"userid" => "58",
						"status" => "Feeling Happy and get well soon!!!",
						"createdDate" => "2014-03-13 07:06:01"
					],
					[
						"status_id" => "2",
						"reply" => "0",
						"email" => "",
						"userid" => "58",
						"status" => "'Silence is a source of great strength.' - Lao Tsu",
						"createdDate" => "2014-03-13 07:06:01"
					],
					[
						"status_id" => "3",
						"reply" => "0",
						"email" => "",
						"userid" => "58",
						"status" => "If you have the power to make someone happy, do it. The world needs more of that. That's what my tweets are for. RT if you love it. Love u.",
						"createdDate" => "2014-03-13 07:06:01"
					]
				]
			];
			
		}
		return $rdata;
	}

	public function postListchallenges()
	{
		$rdata = [
			"status" => "failure",
			"statusMessage" => "User timeline not found for this ID"
		];
		
		if ( Input::has("userid") && Input::get("userid") == $this->dummyuserid ){
			$rdata["status"] = "success";
			
			$rdata["data"] = [			
				"coins" => 250,
				"challenges" => [
					[
						"challenge_id" => "1",
						"coins" => 200,
						"challengeFrom" => $this->dummyuserid,
						"challengeTo" => 58,
						"challengeFromMsg" => "Do you take the challenge?",
						"challengeToMsg" => "I Accept",
						"createdDate" => "2014-03-13 07:06:01",
						"challengeStatus" => 0,
						"challengeWinner" => ''
					],
					[
						"challenge_id" => "2",
						"coins" => 100,
						"challengeFrom" => $this->dummyuserid,
						"challengeTo" => 58,
						"challengeFromMsg" => "Do you have the guts?",
						"challengeToMsg" => "Yes",
						"createdDate" => "2014-03-13 07:06:01",
						"challengeStatus" => 1,
						"challengeWinner" => ''
					],
					[
						"challenge_id" => "3",
						"coins" => 250,
						"challengeFrom" => 58,
						"challengeTo" => $this->dummyuserid,
						"challengeFromMsg" => "Dare to accept?",
						"challengeToMsg" => "Bring it ONN",
						"createdDate" => "2014-03-13 07:06:01",
						"challengeStatus" => 1,
						"challengeWinner" => ''
					],
					[
						"challenge_id" => "4",
						"coins" => 50,
						"challengeFrom" => 58,
						"challengeTo" => $this->dummyuserid,
						"challengeFromMsg" => "Lets see what you got?",
						"challengeToMsg" => "Okay",
						"createdDate" => "2014-03-13 07:06:01",
						"challengeStatus" => 2,
						"challengeWinner" => 58
					]
				]
			];
			
		}
		return $rdata;
	}
	

}