<?php

namespace App\Models;

use App\Models\User\User;
use App\Trait\BelongsToSolicitor;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Note extends Model {
    protected $table = 'notes';
    protected $fillable = [
        'solicitor_id',
        'user_id',
        'note',
        'is_primary'
    ];

    protected $casts = [
        'is_primary' => 'boolean'
    ];

    use BelongsToSolicitor, SoftDeletes;

    public function user() {
        return $this->belongsTo(User::class);
    }

    public function owner() {
        return $this->morphTo();
    }

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