<?php

/** @CreatedBy : Mohit Jain
 *  @Description : User Model Functions
 */

namespace PointToPoint\Model;

use Application\Controller\RestAPIClientController;
use Zend\Session\Container;
use Zend\Json\Json;

class Point extends RestAPIClientController {

    public function apiUrl() {
        $config = new \Zend\Config\Config(include BASE_PATH . '/config/autoload/global.php');
        return $config->api->url;
    }


    public function getFareData($base_vehicle_id,$modelType) {
        $val = '{"where":{"and": [{"base_vehicle_id": "'.$base_vehicle_id.'"},{"status": "1"}]}}';
        $val = rawurlencode($val);
        $url = $this->apiUrl() . "/".$modelType."?&filter=" . $val;
        $resp = $this->get($url);
        return $data = Json::decode($resp->getBody(), true);
    }


    public function getMarkupGrade($gradeArray) {
        $grade="";
        if ($gradeArray['userTypeId'] == 1) {
            if (($gradeArray['userCity'] == $gradeArray['searchCity']) && ($gradeArray['userGender'] == 'Male')) {
                $grade = '1';
            } else if (($gradeArray['userCity'] == $gradeArray['searchCity']) && ($gradeArray['userGender'] == 'Female')) {
                $grade = '2';
            } else if (($gradeArray['userCity'] != $gradeArray['searchCity']) && ($gradeArray['userGender'] == 'Male')) {
                $grade = '3';
            } else if (($gradeArray['userCity'] != $gradeArray['searchCity']) && ($gradeArray['userGender'] == 'Female')) {
                $grade = '4';
            }
        } else if ($gradeArray['userTypeId'] == 7) {
            if (($gradeArray['userCity'] == $gradeArray['searchCity']) && ($gradeArray['userGender'] == 'Male')) {
                $grade = '1';
            } else if (($gradeArray['userCity'] == $gradeArray['searchCity']) && ($gradeArray['userGender'] == 'Female')) {
                $grade = '2';
            } else if (($gradeArray['userCity'] != $gradeArray['searchCity']) && ($gradeArray['userGender'] == 'Male')) {
                $grade = '3';
            } else if (($gradeArray['userCity'] != $gradeArray['searchCity']) && ($gradeArray['userGender'] == 'Female')) {
                $grade = '4';
            }
        }
        return $grade;
    }

    public function getCompanyMarkup($companyId, $cityId, $masterPackageType, $grade) {
        $markup_data = $this->apiUrl() . "/markup/getCompanyMarkup?company_id=" . $companyId . "&city_id=" . $cityId . "&master_package_id=" . $masterPackageType . "&user_grade=" . $grade;
        $markupValue = $this->get($markup_data);
        $markupData = Json::decode($markupValue->getBody(), true);
        if ($markupData['responsedata']['status'] == "failed") {
            $markup_data = $this->apiUrl() . "/markup/getCompanyMarkup?company_id=" . $companyId . "&city_id=" . $cityId . "&master_package_id=0&user_grade=" . $grade;
            $markupValue = $this->get($markup_data);
            $markupData = Json::decode($markupValue->getBody(), true);
        }else if($markupData['responsedata']['status'] == "failed"){
            $markup_data = $this->apiUrl() . "/markup/getCompanyMarkup?company_id=" . $companyId . "&user_grade=" . $grade;
            $markupValue = $this->get($markup_data);
            $markupData = Json::decode($markupValue->getBody(), true);
        }
        if ($markupData['responsedata']['status'] == "success") {
            $markupData = $markupData['responsedata']['data'][0];
        } else {
            $markupData = [];
        }
        //echo '<pre>';print_r($markupData);die();
        return $markupData;
    }




}
