<?php

namespace App\Models\Claim;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Status extends Model {
    use SoftDeletes;

    protected $fillable = [
        'display_name',
        'description',
        'colour',
        'sort_order',
    ];

    public function claims() {
        return $this->hasMany(Claim::class);
    }

    public function hasClaims(): bool {
        return $this->claims()->exists();
    }

    protected static function boot() {
        parent::boot();
        static::addGlobalScope('order', function (Builder $builder) {
            $builder->orderBy('sort_order');
        });
    }
}