<?php

namespace App\Models;

use App\Models\Scopes\ScoalaThroughElevScope;
use App\Models\Traits\LogsActivity;
use Illuminate\Database\Eloquent\Model;

class Nota extends Model
{
    use LogsActivity;
    protected $table = 'note';

    protected static function booted(): void
    {
        static::addGlobalScope(new ScoalaThroughElevScope());
    }

    protected $fillable = [
        'elev_id',
        'materie_id',
        'valoare',
        'data',
        'semestru',
        'tip',
        'observatii',
        'adaugat_de',
        'adaugat_la',
        'modificat_de',
        'modificat_la',
        'motiv_modificare',
    ];

    protected $casts = [
        'data' => 'date',
        'adaugat_la' => 'datetime',
        'modificat_la' => 'datetime',
    ];

    public function elev()
    {
        return $this->belongsTo(Elev::class);
    }

    public function materie()
    {
        return $this->belongsTo(Materie::class);
    }

    public function adaugatDe()
    {
        return $this->belongsTo(User::class, 'adaugat_de');
    }

    public function modificatDe()
    {
        return $this->belongsTo(User::class, 'modificat_de');
    }
}