<?php

namespace app\admin\validate\asset;

use support\Validate;

class HouseTypeValidate extends Validate
{
    protected $rule = [
        'asset_id' => 'require',
        'join_asset_category_id|所属分类' => 'integer',
        'asset_key|资产标识' => 'require|alphaDash',
        'asset_classify|归类' => 'max:32',
        'asset_status|状态' => 'require|in:ACTIVED,DISABLED',
        'asset_category|分类' => 'max:32',
        'asset_house_type|户型' => 'max:32',
        'asset_area_building|建筑面积' => 'float',
        'asset_area_floorage|室内面积' => 'float',
        'asset_area_shared|公摊面积' => 'float',
        'asset_remark|备注' => 'max:128',
        'asset_extend_json' => 'isJson'
    ];

    protected $message = [];

    protected $scene = [
        'add' => ['join_asset_category_id', 'asset_key', 'asset_classify', 'asset_status', 'asset_category', 'asset_house_type', 'asset_area_building', 'asset_area_floorage', 'asset_area_shared', 'asset_remark', 'asset_extend_json'],
        'update' => ['asset_id', 'join_asset_category_id', 'asset_key', 'asset_classify', 'asset_status', 'asset_category', 'asset_house_type', 'asset_area_building', 'asset_area_floorage', 'asset_area_shared', 'asset_remark', 'asset_extend_json'],
    ];

    public function isJson($value)
    {
        if (is_json($value)) {
            return true;
        }
        return '数据格式错误~';
    }
}