/**
  * @api {post} /products POST /products
  * @apiExample Example usage:
  * curl -i -X POST "http://apibeta.compargo.com/v1/products/?countryCode=ph&language=en"
  *      -H "X-COMPARE-REST-API-KEY: 1234567890"
  *      -d "channelId=a1d14206-1ea9-11e4-b32d-eff91066cccf&
  *          brandId=1c28fefa-319b-11e4-988c-7d9574853fac&
  *          name=Visa%20Gold&
  *          featured=0&
  *          status=1"
  * 
  * @apiDescription  Create a new Product
  * @apiName         Post
  * @apiGroup        Products
  *
  * @apiHeader       {String} X-COMPARE-REST-API-KEY   Product unique access-key.
  *
  * @apiParam        {String} language                 Mandatory Language.
  * @apiParam        {String} countryCode              Mandatory Country code.
  * @apiParam        {String} channelId                Mandatory Channel ID of Product.
  * @apiParam        {String} brandId                  Mandatory Brand ID of Product.
  * @apiParam        {String} name                     Mandatory Name of the Product.
  * @apiParam        {String} [description]            Optional Description of the Product.
  * @apiParam        {String} [alias]                  Optional Alias of the Product.
  * @apiParam        {String} [feaured=0]              Optional Featured Value of the Product.
  * @apiParam        {String} [icon=0]                 Optional Icon of the Product.
  * @apiParam        {String} [perPage]                Optional Per Page of the Product.
  * @apiParam        {String} [status=0]               Optional Status of the Product.
  * @apiParam        {String} [createdBy]              Optional ID of the User who created the Product.
  * @apiParam        {String} [modifiedBy]             Optional ID of the User who modified the Product.
  *	
  * @apiSuccess      {String} id                       The new Product-ID.
  *
  * @apiSuccessExample Success-Response:
  *     HTTP/1.1 200 OK
  *     {
  *       "id": "f77cf470-3bdc-11e4-b18a-fe7344fb1ea4"
  *     }
  *     
  * @apiError BadInputParameter The request cannot be fulfilled due to bad syntax.
  *
  * @apiErrorExample Error-Response:
  *     HTTP/1.1 400
  *     {
  *       "error": "BadInputParameter"
  *     }
  *     
  * @apiError InvalidAccessToken The access token is invalid.
  *
  * @apiErrorExample Error-Response:
  *     HTTP/1.1 401 Unauthorized
  *     {
  *       "error": "InvalidAccessToken"
  *     }
  *
  * @apiError MissingAuthenticationCredentials The authentication credentials are missing.
  *
  * @apiErrorExample Error-Response:
  *     HTTP/1.1 401 Unauthorized
  *     {
  *       "error": "MissingAuthenticationCredentials"
  *     }
  *     
  * @apiError RouteNotFound That route was not found on the server.
  *
  * @apiErrorExample Error-Response:
  *     HTTP/1.1 404 
  *     {
  *       "error": "RouteNotFound"
  *     }
  */
 public function post()
 {
     $results = array();
     $request = $this->di->get('request');
     $data = $request->getPost();
     if (!empty($data)) {
         $product = new Products();
         $data['id'] = $product->id;
         $data['channelId'] = isset($data['channelId']) ? $data['channelId'] : '';
         $data['brandId'] = isset($data['brandId']) ? $data['brandId'] : '';
         $data['name'] = isset($data['name']) ? $data['name'] : '';
         $data['alias'] = isset($data['alias']) ? $data['alias'] : '';
         $data['description'] = isset($data['description']) ? $data['description'] : '';
         $data['featured'] = isset($data['featured']) ? $data['featured'] : '';
         $data['icon'] = isset($data['featured']) ? $data['featured'] : '';
         $data['language'] = isset($data['language']) ? $data['language'] : '';
         $data['status'] = isset($data['status']) ? $data['status'] : '';
         if (isset($data['status'])) {
             $data['active'] = $data['status'] != Products::ACTIVE ? 0 : 1;
         }
         $data['createdBy'] = isset($data['createdBy']) ? $data['createdBy'] : '';
         $data['modifiedBy'] = isset($data['modifiedBy']) ? $data['modifiedBy'] : '';
         if ($product->save($data)) {
             $results['id'] = $product->id;
         } else {
             throw new HTTPException("Request unable to be followed due to semantic errors", 422, array('dev' => $product->getMessages(), 'internalCode' => 'P1000', 'more' => ''));
         }
     } else {
         throw new HTTPException("The request cannot be fulfilled due to bad syntax.", 400, array('dev' => 'A required field is missing.', 'internalCode' => 'P1000', 'more' => ''));
     }
     return $results;
 }