<?php

namespace App\Models\Objects\Values;

class BooleanValue extends Value {
    protected $table = 'field_boolean_values';

    public function get() {
        return is_null($this->value) ? null : boolval($this->value);
    }
    public function set($value): bool {
        if ($value === 'false') $value = false;
        if ($value === 'null') $value = null;
        return parent::set(is_null($value) ? null : boolval($value));
    }

    public static function applyFilter($query, $value) {
        parent::applyFilter($query, ($value === 'yes'));
    }
}