<?php
/**
+-----------------------------------------------------------------------------------------------------------------------
 * 模型层:区域-房间 模型类
+-----------------------------------------------------------------------------------------------------------------------
 *
 * PHP version 7
 *
 * @category  App\Models\Area
 * @package   App\Models\Area
 * @author    Richer <yangzi1028@163.com>
 * @date      2021年6月16日15:10:38
 * @copyright 2020-2022 Richer (http://www.Richer.com/)
 * @license   http://www.Richer.com/ License
 * @link      http://www.Richer.com/
 */
namespace App\Models\Area;

use App\Models\BaseModel;
use App\Models\Traits\AreaTrait;
use Encore\Admin\Auth\Database\Administrator;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Arr;
use phpDocumentor\Reflection\DocBlock\Tags\Param;

/**
 * Class Room
 *
 * @category  App\Models\Area
 * @package   App\Models\Area
 * @author    Richer <yangzi1028@163.com>
 * @date      2021年6月16日15:10:38
 * @copyright 2020-2022 Richer (http://www.Richer.com/)
 * @license   http://www.Richer.com/ License
 * @link      http://www.Richer.com/
 */
class Area extends BaseModel
{
    // 指定数据库表
    const TABLE = '';
    protected $table = self::TABLE;

    // 指定对象显示名称:方便系统统一查询和做其他处理
    const OBJ_NAME      = 'area';
    const OBJ_NAME_ZH   = '区域';

    // 级别
    const LEVEL = 0;

    const PROVINCE  = Province::OBJ_NAME;
    const CITY      = City::OBJ_NAME;
    const COUNTY    = County::OBJ_NAME;
    const TOWNSHIP  = Township::OBJ_NAME;
    const VILLAGE   = Village::OBJ_NAME;
    const GROUP     = Group::OBJ_NAME;

    const PROVINCE_ZH   = Province::OBJ_NAME_ZH;
    const CITY_ZH       = City::OBJ_NAME_ZH;
    const COUNTY_ZH     = County::OBJ_NAME_ZH;
    const TOWNSHIP_ZH   = Township::OBJ_NAME_ZH;
    const VILLAGE_ZH    = Village::OBJ_NAME_ZH;
    const GROUP_ZH      = Group::OBJ_NAME_ZH;


    /**
     * 用户状态业务常量配置
     */
    const ENABLE    = 1;// 有效
    const DISABLE   = 0;// 禁用

    const LEVEL_PROVINCE    = Province::LEVEL;
    const LEVEL_CITY        = City::LEVEL;
    const LEVEL_COUNTY      = County::LEVEL;
    const LEVEL_TOWNSHIP    = Township::LEVEL;
    const LEVEL_VILLAGE     = Village::LEVEL;
    const LEVEL_GROUP       = Group::LEVEL;

    /**
     * 用户状态业务常量配置[1 => '有效', 2 => '禁用']
     */
    const STATUS_OPTIONS = [
        self::ENABLE    => '有效',
        self::DISABLE   => '禁用',
    ];

    /**
     * 用户状态颜色业务常量配置[1 => '待支付', 2 => '已完成', 3 => '已取消']
     */
    const STATUS_COLOR_OPTIONS = [
        self::ENABLE    => 'success',
        self::DISABLE   => 'danger',
    ];

    // 用于laravel-admin switch 控件
    const STATUS_STATES = [
        'on'  => [
            'value' => self::ENABLE,
            'text'  => self::STATUS_OPTIONS[self::ENABLE],
            'color' => 'success'
        ],
        'off' => [
            'value' => self::DISABLE,
            'text'  => self::STATUS_OPTIONS[self::DISABLE],
            'color' => 'default'
        ],
    ];

    /**
     * 访问器被附加到模型数组的形式。
     *
     * @var array
     */
    protected $appends = ['status_show'];

    /**
     *
     */
    public static function boot()
    {
        parent::boot();

        // 删除
        static::deleted(function ($model) {
            // 删除关联
//            AreaTrait::deleteArea($model);
        });
    }

    /**
     * 获取状态的中文显示
     *
     * @return mixed
     */
    public function getStatusShowAttribute()
    {
        return Arr::get(self::STATUS_OPTIONS, $this->status ? : self::ENABLE);
    }
}