public function rules()
    {
        return [
            [['id', 'type_id', 'state_id', 'object_id', 'client_id', 'seller_id'], 'integer'],
            [['client', 'seller', 'title', 'description'], 'safe'],
            [['create_time', 'update_time'], 'safe'],
            [['type', 'state'], 'safe'],
            [['filename'], 'string'],

            [['client', 'attachment'], 'safe', 'on' => ['create']],
            [['type', 'title'], 'required', 'on' => ['create', 'update']],
            [['description', 'status_types'], 'safe', 'on' => ['create', 'update']],
            [['file_id'], 'integer', 'on' => ['create', 'update']],
            [
                ['validity_start', 'validity_end'],
                'safe',
                'on' => ['create', 'update'],
                'when' => function () {
                    return Yii::$app->user->can('document.update');
                },
            ],
            [
                ['validity_end'],
                'compare',
                'compareAttribute' => 'validity_start',
                'operator' => '>',
                'on' => ['create', 'update'],
                'enableClientValidation' => false,
                'when' => function () {
                    return Yii::$app->user->can('document.update');
                },
            ],
            [['id'], 'required', 'on' => ['update', 'delete']],
            [['data'], JsonValidator::class],
        ];
    }
public function rules()
    {
        return [
            [['id', 'type_id', 'state_id', 'object_id', 'client_id', 'seller_id'], 'integer'],
            [['client', 'seller', 'title', 'description'], 'safe'],
            [['create_time', 'update_time'], 'safe'],
            [['type', 'state'], 'safe'],
            [['filename'], 'string'],

            [['client', 'attachment'], 'safe', 'on' => ['create']],
            [['type', 'title'], 'required', 'on' => ['create', 'update']],
            [['description', 'status_types'], 'safe', 'on' => ['create', 'update']],
            [['file_id'], 'integer', 'on' => ['create', 'update']],
            [
                ['validity_start', 'validity_end'],
                'safe',
                'on' => ['create', 'update'],
                'when' => function () {
                    return Yii::$app->user->can('document.update');
                },
            ],
            [
                ['validity_end'],
                'compare',
                'compareAttribute' => 'validity_start',
                'operator' => '>',
                'on' => ['create', 'update'],
                'enableClientValidation' => false,
                'when' => function () {
                    return Yii::$app->user->can('document.update');
                },
            ],
            [['id'], 'required', 'on' => ['update', 'delete']],
            [['data'], JsonValidator::class],
        ];
    }
{@inheritdoc}