<?php 

class Validation_app_model extends CI_Model {
	public $validation_array = array(
			'login'=> array('email'=>array('required'=>array('code'=>'ER02', 'message'=>'Email id is null or empty'),
			'email'=>array('code'=>'ER03', 'message'=>'Invalid Email id')),
			'password'=>array('required'=>array('code'=>'ER04', 'message'=>'Password is null or empty')),
			'country_id'=>array('required'=>array('code'=>'ER05','message'=>'Country Id is null or empty'))),
			'check_email_availability'=> array('email'=>array('required'=>array('code'=>'ER02', 'message'=>'Email id is null or empty'),
			'email'=>array('code'=>'ER03', 'message'=>'Invalid Email id')),
			'phone'=>array('required'=>array('code'=>'ER07', 'message'=>'Phone no is null or empty'),
			'phone'=>array('code'=>'ER08', 'message'=>'Invalid Phone no')),),
			'registration'=> array('email'=>array('required'=>array('code'=>'ER02', 'message'=>'Email id is null or empty'),
			'email'=>array('code'=>'ER03', 'message'=>'Invalid Email id')),
			'phone'=>array('required'=>array('code'=>'ER07', 'message'=>'Phone no is null or empty'),
			'phone'=>array('code'=>'ER08', 'message'=>'Invalid Phone no'),),
			'name'=>array('required'=>array('code'=>'ER04', 'message'=>'Name is null or empty'),),
			'password'=>array('required'=>array('code'=>'ER04','message'=>'Password is null or empty')),
			'password'=>array('required'=>array('code'=>'ER04','message'=>'Password is null or empty'))),
			'get_events_list'=>array('auth_token'=>array('required'=>array('code'=>'ER17', 'message'=>'User Id is null or empty'),)),
			'filters'=>array('auth_token'=>array('required'=>array('code'=>'ER17', 'message'=>'User Id is null or empty'),)),
			'events_details'=>array('auth_token'=>array('required'=>array('code'=>'ER17', 'message'=>'User Id is null or empty'),)),
			'get_category_list'=>array('auth_token'=>array('required'=>array('code'=>'ER17', 'message'=>'User Id is null or empty'),)),
			'event_search'=>array(),
			'get_last_booking'=>array('auth_token'=>array('required'=>array('code'=>'ER17', 'message'=>'User Id is null or empty'),)),
			'user_language'=> array('auth_token'=>array('required'=>array('code'=>'ER17', 'message'=>'User Id is null or empty')),
			'language'=>array('required'=>array('code'=>'ER16', 'message'=>'Language is null or empty')),),
			'add_favorites'=> array('auth_token'=>array('required'=>array('code'=>'ER17', 'message'=>'User Id is null or empty')),
			'event_id'=>array('required'=>array('code'=>'ER16', 'message'=>'Event id is null or empty')),),
			'get_cities_list'=>array('auth_token'=>array('required'=>array('code'=>'ER19', 'message'=>'User Id is null or empty'),)),
			'update_city'=>array('auth_token'=>array('required'=>array('code'=>'ER19', 'message'=>'User Id is null or empty'),)),
			'booking_summary'=>array('auth_token'=>array('required'=>array('code'=>'ER17', 'message'=>'User Id is null or empty'),)),
			'payment'=> array('auth_token'=>array('required'=>array('code'=>'ER17', 'message'=>'User Id is null or empty')),
			'booking_id'=>array('required'=>array('code'=>'ER34', 'message'=>'Booking id is null or empty'))),
			'event_rating'=> array('auth_token'=>array('required'=>array('code'=>'ER17', 'message'=>'User Id is null or empty')),
			'rating'=>array('required'=>array('code'=>'ER26', 'message'=>'Rating is null or empty')),
			'event_id'=>array('required'=>array('code'=>'ER27', 'message'=>'Event id is null or empty')),
			'description'=>array('required'=>array('code'=>'ER28', 'message'=>'description id is null or empty')),),
			'update_notification_email_status'=>array('auth_token'=>array('required'=>array('code'=>'ER17',
			'message'=>'User Id is null or empty'),)),
			'get_app_version'=>array(),
			'logout'=>array('auth_token'=>array('required'=>array('code'=>'ER17', 'message'=>'User Id is null or empty'))),
			'profile_details'=>array('auth_token'=>array('required'=>array('code'=>'ER17', 'message'=>'User Id is null or empty'))),
			'profile_edit'=> array('auth_token'=>array('required'=>array('code'=>'ER17', 'message'=>'User Id is null or empty')),),
			'booking'=> array('auth_token'=>array('required'=>array('code'=>'ER17', 'message'=>'User Id is null or empty')),
			'event_id'=>array('required'=>array('code'=>'ER20', 'message'=>'Event id is null or empty')),
			'customer_id'=>array('required'=>array('code'=>'ER29', 'message'=>'Customer id is null or empty')),
			'event_date_id'=>array('required'=>array('code'=>'ER30', 'message'=>'Event date id is null or empty')),
			'no_of_ticket'=>array('required'=>array('code'=>'ER31', 'message'=>'Number of ticket is null or empty')),
			'ticket_details'=>array('required'=>array('code'=>'ER32', 'message'=>'Ticket details is null or empty')),
			'amount'=>array('required'=>array('code'=>'ER33', 'message'=>'Amount is null or empty')),),
			'cancel_booking'=> array('auth_token'=>array('required'=>array('code'=>'ER17', 'message'=>'User Id is null or empty')),
			'booking_id'=>array('required'=>array('code'=>'ER34', 'message'=>'Booking Id is null or empty')),),
			'update_fcm_token'=> array('auth_token'=>array('required'=>array('code'=>'ER17', 'message'=>'User Id is null or empty')),
			'fcm_token'=>array('required'=>array('code'=>'ER16', 'message'=>'Fcm token is null or empty')),),
			'get_favorites_list'=>array('auth_token'=>array('required'=>array('code'=>'ER17', 'message'=>'User Id is null or empty'),)),
			'get_booking_list'=>array('auth_token'=>array('required'=>array('code'=>'ER17', 'message'=>'User Id is null or empty'),)),
			'settings'=>array('auth_token'=>array('required'=>array('code'=>'ER17', 'message'=>'User Id is null or empty'),)),
			'forgot_password'=> array('new_password'=>array('required'=>array('code'=>'ER35', 'message'=>'New password is null or empty')),
			'phone'=>array('required'=>array('code'=>'ER07', 'message'=>'Phone is null or empty')),),
			'convertCurrency'=> array(),
			'sync_contacts' => array(
				'auth_token' => array(
					'required' => array(
						'code' => 'ER02',
						'message' => 'User id is null or empty'
					)
				),
				'contacts' => array(
					'required' => array(
						'code' => 'ER04',
						'message' => 'Contacts is null or empty'
					),
				)
			),
			'update_friend_request' => array(
				'auth_token' => array(
					'required' => array(
						'code' => 'ER02',
						'message' => 'User id is null or empty'
					)
				),
				'user_id' => array(
					'required' => array(
						'code' => 'ER04',
						'message' => 'User Id is null or empty'
					),
				),
				'add_as_friend' => array(
					'required' => array(
						'code' => 'ER04',
						'message' => 'Accept/Reject value is null or empty'
					),
				)
			),
			'send_friend_request' => array(
				'auth_token' => array(
					'required' => array(
						'code' => 'ER02',
						'message' => 'User id is null or empty'
					)
				),
				'user_id' => array(
					'required' => array(
						'code' => 'ER04',
						'message' => 'User Id is null or empty'
					),
				)
			),
			'get_friend_requests' => array(
				'auth_token' => array(
					'required' => array(
						'code' => 'ER02',
						'message' => 'User id is null or empty'
					)
				)
			),
			'recent_chats' => array(
				'auth_token' => array(
					'required' => array(
						'code' => 'ER02',
						'message' => 'User id is null or empty'
					)
				)
			),
			'upload_audio_message' => array(
				'auth_token' => array(
					'required' => array(
						'code' => 'ER02',
						'message' => 'User id is null or empty'
					)
				) 
			),
			'getCountry' => array(),
			'validate_promo_code'=>array(
				'auth_token' => array(
					'required' => array(
						'code' => 'ER02',
						'message' => 'User id is null or empty'
					)
				),
				'event_id' => array(
					'required' => array(
						'code' => 'ER04',
						'message' => 'Event Id is null or empty'
					),
				),
				'promo_code' => array(
					'required' => array(
						'code' => 'ER02',
						'message' => 'Promocode is null or empty'
					)
				),
				'no_of_tickets' => array(
					'required' => array(
						'code' => 'ER04',
						'message' => 'No of Ticket is null or empty'
					)
				),
				'seat_class' => array(
					'required' => array(
						'code' => 'ER04',
						'message' => 'Seat Class is null or empty'
					),
				),
				'tot_cost' => array(
					'required' => array(
						'code' => 'ER04',
						'message' => 'Total Cost is null or empty'
					)
				)
			)
		);

	public function validation_check($method_name, $parms) {
 		$state = 0;
 		$rules = $this->validation_array[$method_name]; 		
 		$error_key = '';
 		foreach ($rules as $key => $value) {
 			foreach ($value as $keys => $values) {
 				switch ($keys) {
 						case 'required':
 							if(!isset($parms[$key]) || $parms[$key]=='' || $parms[$key]== null){
 								$state = 1;
 								$error_key = $values;
 							} 
 							break;
 						case 'email':
 							if (isset($parms[$key]) && !filter_var($parms[$key], FILTER_VALIDATE_EMAIL)) {
	  							$state = 1;
 								$error_key = $values; 
							} 
 							break;
 						case 'phone':
 							if(isset($parms[$key])){
 							$phone = preg_replace('/[^0-9]/', '', $parms[$key]);
	 							/*if (strlen($phone) !== 10) {
		  							$state = 1;
	 								$error_key = $values; 
								} */
							} 
 							break;


 						
 						default:
 							# code...
 							break;
 					}
 					if($state==1){
 						break;
 					}
 			}
 			if($state==1){
 				break;
 			}
 		}
 		return array('state'=>$state,'response'=>$error_key);
 	} 	
}
?>
