<?php
/**
 * Created by PhpStorm.
 * User: sunmoon<i@liming.me>
 * Date: 2019/07/29
 * Time: 上午9:39
 */


namespace common\libs\logging\operate\valueType;
use common\helpers\Config as ConfigHelper;

class Area extends AbstractValueType {

    public function format(){
        $value = $this->getValue();
        if(!$value){
            return null;
        }
        $count = count($value);
        switch ($count){
            case 1:
                $data = ($value[0] > 0) ? ConfigHelper::province($value[0]) : $this->defaultText;
                break;
            case 2:
                $data = ($value[0] > 0 && $value[1] > 0) ? ConfigHelper::city($value[0], $value[1]) : $this->defaultText;
                break;
            case 3:
                $data = ($value[0] > 0 && $value[1] > 0 && $value[2] > 0) ? ConfigHelper::county($value[0], $value[1], $value[2]) : $this->defaultText;
                break;
            default:
                $data = null;
                break;
        }
        return ($data && isset($data['REGION_NAME'])) ? $data['REGION_NAME'] : $this->defaultText;
    }
    public function result(){
        return $this->format();
    }
}