<?php

loadController('base/module');

class ControllerShippingFrenet extends ControllerBaseModule {
	protected $referencePathFile = 'shipping/frenet';

	protected function loadData() {
		$this->load->type('tipocomum');
		$this->load->type('tipofrete');

		$this->dataVue['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones();
		$this->dataVue['Type_Status'] = Type_Status::getEnumList();
		$this->dataVue['Type_DsimDnao'] = Type_DsimDnao::getEnumList();
		$this->dataVue['configurations'] = $this->model_setting_setting->getSetting('frenet');
	}

	protected function loadModel() {
		$this->load->model('setting/setting');
		$this->load->model('localisation/geo_zone');
	}

	protected function validate() {
		$this->loadLanguage();
		$this->load->type('tipocomum');

		extract($this->request->post);

		$errors = [];

		$errors = $this->validate->execute([
			'frenet_descricao' => [
				'value' => $frenet_descricao,
				'validates' => ['isEmpty']
			],
			'frenet_token' => [
				'value' => $frenet_token,
				'validates' => ['isEmpty']
			],
			'frenet_cep_origem' => [
				'value' => $frenet_cep_origem,
				'validates' => ['isEmpty', 'isCep']
			],
			'frenet_sort_order' => [
				'value' => $frenet_sort_order,
				'validates' => ['isIntegerNumber']
			],
			'frenet_geo_zone_id' => [
				'value' => $frenet_geo_zone_id,
				'validates' => ['isEmpty']
			],
			'frenet_status' => [
				'value' => $frenet_status,
				'validates' => ['isEmpty', 'isEnabledOrDisabled']
			],
		]);

		return $errors;
	}
}