<?php

namespace OfficeBrain\Bundle\CoreBundle\Controller;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Nelmio\ApiDocBundle\Annotation\ApiDoc;

/**
 * @author Employee Id: 410175
 *        
 *         Desciption: Core Mobile API
 *        
 * @param
 *        	NULL
 *
 * @throws null @Route("/api/v1", defaults={"_format" = "json"})
 */
class ApiCoreController extends Controller
{
	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
     *
     * @throws null
     */
    public function __construct()
    {
        $this->request = null;
        $this->projectSetting = null;
        $this->coreManager = null;
    }

    /**
     * @author Employee Id: 410175
     *
     * Desciption: Unset member variables
     *
     * @param null
     *
     * @throws null
     */
    public function __destruct()
    {
        unset($this->request);
        unset($this->projectSetting);
        unset($this->coreManager);
    }

    /**
     * @author Employee Id: 410175
     *
     * Desciption: Create and initialize various required object and member variables
     *
     * @param null
     *
     * @throws null
     */
    public function initAction()
    {
        $this->request = $this->getRequest();
        $this->projectSetting = $this->request->get('project_setting');
        $this->coreManager = $this->container->get('office_brain_core_manager');
        $this->userManager = $this->container->get('office_brain_user_manager');
    }

    /**
     * @author Employee Id: 410175
     * OB eCommerce Product - Core Mobile API
     *
     * @Route("/{_locale}/get-project-settings",
     * 	name="office_brain_apicorebundle_get_project_settings"
     * )
     *
     * @ApiDoc(
     *      resource=true,
     *      section="Core",
     *      description="Get All the Project Settings.",
     *      statusCodes={
     *              1="Returned when success",
     *              403="Returned when the user is not authorized to see this link",
     *              0="Returned when form validation is failed",
     *      },
     *      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"},
     *      },
     * )
     *
     * @Method({"GET"})
     */
     public function getProjectSettingsAction()
     {
	     $this->initAction();
	    
	     return array(
		     'status' => self::SUCCESS,
		     'status_code' => self::SUCCESS_CODE,
		     'response_data' => $this->projectSetting,
	     );
     }
    
     
     /**
      * @author Employee Id: 410175
      * OB eCommerce Product - Core API
      *
      * @Route("/{_locale}/get-all-country",
      * 	name="office_brain_apicorebundle_get_all_country"
      * )
      *
      * @ApiDoc(
      *      resource=true,
      *      section="Core",
      *      description="Get All the country Data.",
      *      statusCodes={
      *              1="Returned when success",
      *              403="Returned when the user is not authorized to see this link",
      *              0="Returned when form validation is failed",
      *      },
      *      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"},
      *      }
      * )
      *
      * @Method({"GET"})
      */
	public function getAllCountryAction() 
	{
		$this->initAction ();
				
		return array (
				'status' => self::SUCCESS,
				'status_code' => self::SUCCESS_CODE,
				'response_data' => $this->coreManager->getCountryDataAPI (  ) 
		);
	}
   
    /**
     * @author Employee Id: 410175
     * OB eCommerce Product - Core API
     *
     * @Route("/{_locale}/get-state-by-country/{country_id}",
     * 	name="office_brain_apicorebundle_get_state_by_country"
     * )
     *
     * @ApiDoc(
     *      resource=true,
     *      section="Core",
     *      description="Get State By Country ID",     
     *      statusCodes={
     *              1="Returned when success",
     *              403="Returned when the user is not authorized to see this link",
     *              0="Returned when form validation is failed",
     *      },
     *      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"},
     *      } 
     * )
     *
     * @Method({"GET"})
     */ 
    public function getStateByCountryAction($country_id)
    {
        $this->initAction();
        
        if (isset($country_id) && $country_id > 0) {
            return array(
                    'status' => self::SUCCESS,
                    'status_code' => self::SUCCESS_CODE,
                    'response_data' => $this->coreManager->getStateDataAPI($country_id),
            );
        } else {
            return array(
                    'status' => self::ERROR,
                    'status_code' => self::ERROR_CODE,
                    'message' => 'Enter Country Id',
            );
        }
    }
    
    /**
     * @author Employee Id: 410175
     * OB eCommerce Product - Core API
     *
     * @Route("/{_locale}/get-city-by-state-country/{state_id}/{country_id}",
     * 	name="office_brain_apicorebundle_get_city_by_state"
     * )
     *
     * @ApiDoc(
     *      resource=true,
     *      section="Core",
     *      description="Get City By State ID & CountryID",
     *      statusCodes={
     *              1="Returned when success",
     *              403="Returned when the user is not authorized to see this link",
     *              0="Returned when form validation is failed",
     *      },
     *      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"},
     *      }
     * )
     *
     * @Method({"GET"})
     */
    public function getCityByStateAction($state_id, $country_id)
    {
        $this->initAction();
        
        if (isset($state_id) && $state_id > 0 && isset($country_id) && $country_id > 0) {
            return array(
                    'status' => self::SUCCESS,
                    'status_code' => self::SUCCESS_CODE,
                    'response_data' => $this->coreManager->getCityDataAPI($state_id, $country_id),
            );
        } else {
            return array(
                    'status' => self::ERROR,
                    'status_code' => self::ERROR_CODE,
                    'message' => 'Enter State Id & Country Id',
            );
        }
    }
    
    
    /*
     * @author Employee Id: 410175
     * OB eCommerce Product - Core API
     *
     * @Route("/{_locale}/get-distributor-state/",
     * 	name="office_brain_apicorebundle_get_distributor_state"
     * )
     *
     * @ApiDoc(
     *      resource=true,
     *      section="Core",
     *      description="Get Distributor State ",
     *      statusCodes={
     *              1="Returned when success",
     *              403="Returned when the user is not authorized to see this link",
     *              0="Returned when form validation is failed",
     *      },
     *      requirements={
     *             {"name"="access_token", "dataType"="string", "required"=false, "description"="valid access token"},
     *             {"name"="_locale", "dataType"="string", "required"=true, "default"="en_us"},
     *      }
     * )
     *
     * @Method({"GET"})
     * /
    public function getDistributorStateAction()
    {
        $this->initAction();

        return array(
                'status' => 'success',
                'status_code' => 1,
                'data' => $this->coreManager->getLocateDistributorStateDataAPI(),
        );
    }

    /**
     * @author Employee Id: 410175
     * OB eCommerce Product - Core API
     *
     * @Route("/{_locale}/get-distributor-by-state/{state_id}",
     * 	name="office_brain_apicorebundle_get_distributor_by_state"
     * )
     *
     * @ApiDoc(
     *      resource=true,
     *      section="Core",
     *      description="Get Distributor By State",
     *      statusCodes={
     *              1="Returned when success",
     *              403="Returned when the user is not authorized to see this link",
     *              0="Returned when form validation is failed",
     *      },
     *      requirements={
     *             {"name"="access_token", "dataType"="string", "required"=false, "description"="valid access token"},
     *             {"name"="_locale", "dataType"="string", "required"=true, "default"="en_us"},
     *      }
     * )
     *
     * @Method({"GET"})
     * / 
    public function getDistributorByStateAction($state_id)
    {
        $this->initAction();

        if ($state_id > 0) {
            $data = $this->userManager->getDistributorsAPI(array(
                    'stateId' => $state_id,
            ));
        } else {
            $data = $this->userManager->getDistributorsAPI();
        }

        return array(
                'status' => 'success',
                'status_code' => 1,
                'data' => $data,
        );
    }*/
}
