<?php

namespace OfficeBrain\Bundle\PageBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;

/**
 *
 * @author Employee Id: 410175
 *
 * Desciption: Core Mobile API
 *
 * @param NULL
 *
 * @return NULL
 *
 * @throws NULL
 *
 * @Route("/api/v1/", defaults={"_format" = "json"})
 *
 */
class ApiHomePageMobileController extends HomePageController
{	
	const SUCCESS = 'success';
	const ERROR = 'error';
	const SUCCESS_CODE = 1;
	const ERROR_CODE = 0;
	
	/**
	 *
	 * @author Employee Id: 410175
	 *
	 * Desciption: Define member variables with thier default value
	 *
	 * @param NULL
	 *
	 * @return NULL
	 *
	 * @throws NULL 
	 */
	public function __construct()
	{
		$this->request = null;
		$this->cultureCode = null;
		$this->projectSetting = null;
		$this->coreManager = null;
	}
	
	/**
	 *
	 * @author Employee Id: 410175
	 *
	 * Desciption: Unset member variables
	 *
	 * @param NULL
	 *
	 * @return NULL
	 *
	 * @throws NULL
	 *
	 */
	public function __destruct()
	{
		unset($this->request);
		unset($this->cultureCode);
		unset($this->projectSetting);
		unset($this->coreManager);
	}
	
	/**
	 *
	 * @author Employee Id: 410175
	 *
	 * Desciption: Create and initialize various required object and member variables
	 *
	 * @param NULL
	 *
	 * @return NULL
	 *
	 * @throws NULL
	 *
	 */
	public function initAction()
	{
		parent::initAction();
		$this->request = $this->getRequest();
		$this->projectSetting = $this->request->get('project_setting');
		//$this->cultureCode = $this->projectSetting['culture_code'];
		//$this->bannerManager = $this->get('office_brain_banner_manager');
		//$this->mobileAppManager = $this->get('office_brain_mobileapp_manager');
		//$this->bannerBaseUrl = $this->getParameter('banner.image_url');
		//$this->mobileAppBannerTypeId = $this->getParameter('mobile_app.banner_type_id');
		$this->locale = $this->projectSetting['locale_language'];
	}
	
	
	/**
	 *
	 * @author Employee Id: 410175
	 * Description : Get Brand List
	 *
	 * @param : null
	 *
	 * @return null
	 *
	 * @throws null
	 *
	 * @Route("{_locale}/get-brand-listing", name="office_brain_home_page_brand_list_api")
	 *
	 * @ApiDoc(
	 *      resource=true,
	 *      section="Home Page",
	 *      description="Get Brand Listing",
	 *      requirements = {
	 * 			   {"name"="_locale", "dataType"="string", "required"=true, "default"="en_us"},
     *             {"name"="access_token", "dataType"="string", "required"=true, "description"="valid access token"},
     *             {"name"="instance_id", "dataType"="integer", "required"=true, "description"="valid instance_id"},
     *             {"name"="instance_type", "dataType"="string", "required"=true, "description"="valid instance_type"},
	 *      	   
	 *      },
	 *      statusCodes={
	 *              1="Returned when success",
	 *              403="Returned when the user is not authorized to see this link",
	 *              0="Returned when form validation is failed",
	 *      }
	 * )
	 *
	 * @Method("GET")
	 * @Template()
	 *
	 */
	 public function getBrandListingAction()
	 {
	 	$this->initAction();
	 	
	 	$brandList = null;
	 	$locale=$this->locale;	 	
	 	$arrLocale= $this->splitCulture($locale);
	 	$givenCulture = $this->splitCulture($this->request->getLocale());
	 	
	 	
	 	$tmpBrandList = $this->get('office_brain_subshop_manager')->frontGetBrands($this->get("officebrain_brand_api_manager"),$arrLocale[0],$this->projectSetting['instance_id']);
	 	if (isset($givenCulture[0]) &&  isset($tmpBrandList[$givenCulture[0]]) ){
	 		$brandList = $tmpBrandList[$givenCulture[0]];
	 		$brandList = array_values($brandList);
	 	}
	 	return array(
		     'status' => self::SUCCESS,
		     'status_code' => self::SUCCESS_CODE,
		     'response_data' => $brandList,
	     );
	 }	

	 /**
	  * @author Employee Id: 410175
	  * Description : Get BestSelling List
	  *
	  * @param : null
	  *
	  * @return null
	  *
	  * @throws null
	  *
	  * @Route("{_locale}/get-best-selling", name="office_brain_home_page_best_selling_api")
	  *
	  * @ApiDoc(
	  *      resource=true,
	  *      section="Home Page",
	  *      description="Get Best Selling Product List ",
	  *      requirements = {
	  * 			{"name"="_locale", "dataType"="string", "required"=true, "default"="en_us"},
	  *             {"name"="access_token", "dataType"="string", "required"=true, "description"="valid access token"},
	  *             {"name"="instance_id", "dataType"="integer", "required"=true, "description"="valid instance_id"},
	  *             {"name"="instance_type", "dataType"="string", "required"=true, "description"="valid instance_type"},
	  *
	  *      },
	  *      statusCodes={
	  *              1="Returned when success",
	  *              403="Returned when the user is not authorized to see this link",
	  *              0="Returned when form validation is failed",
	  *      }
	  * )
	  *
	  * @Method("GET")
	  * @Template()
	  *
	  */
	 public function getBestSellingAction()
	 {
	 	$this->initAction();
	 	$bestSelling = parent::getsiteProductBlockAction($block='best_selling_product',$slug='best_selling_product');
	 	return array(
	 			'status' => self::SUCCESS,
	 			'status_code' => self::SUCCESS_CODE,
	 			'response_data' => $bestSelling,
	 	);
	 }
	 
	 /**
	  * @author Employee Id: 410175
	  * Description : Get Recommended Products List
	  *
	  * @param : null
	  *
	  * @return null
	  *
	  * @throws null
	  *
	  * @Route("{_locale}/get-recommended-products", name="office_brain_home_page_recommended_products_api")
	  *
	  * @ApiDoc(
	  *      resource=true,
	  *      section="Home Page",
	  *      description="Get Recommended Products ",
	  *      requirements = {
	  * 			{"name"="_locale", "dataType"="string", "required"=true, "default"="en_us"},
	  *             {"name"="access_token", "dataType"="string", "required"=true, "description"="valid access token"},
	  *             {"name"="instance_id", "dataType"="integer", "required"=true, "description"="valid instance_id"},
	  *             {"name"="instance_type", "dataType"="string", "required"=true, "description"="valid instance_type"},
	  *
	  *      },
	  *      statusCodes={
	  *              1="Returned when success",
	  *              403="Returned when the user is not authorized to see this link",
	  *              0="Returned when form validation is failed",
	  *      }
	  * )
	  *
	  * @Method("GET")
	  * @Template()
	  *
	  */
	 public function getRecommendedProductsAction()
	 {
	 	$recommendedProducts = parent::getsiteProductBlockAction($block='recommend_products',$slug='recommend_products');
	 	return array(
	 			'status' => self::SUCCESS,
	 			'status_code' => self::SUCCESS_CODE,
	 			'response_data' => $recommendedProducts,
	 	);
	 }
	 
	 private function splitCulture($locale) {
	 	return explode("_", $locale);
	 }
}
