<?php

namespace App\Models;

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

class Corigenta extends Model
{
    use LogsActivity;
    protected $table = 'corigente';

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

    protected $fillable = [
        'elev_id',
        'materie_id',
        'perioada_id',
        'media_inainte',
        'nota_corigenta',
        'data_examen',
        'profesor_id',
        'status',
        'observatii',
    ];

    protected $casts = [
        'media_inainte' => 'decimal:2',
        'data_examen' => 'date',
    ];

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

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

    public function perioada()
    {
        return $this->belongsTo(Perioada::class);
    }

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

    public function getStatusLabelAttribute(): string
    {
        return match ($this->status) {
            'programat' => 'Programat',
            'promovat' => 'Promovat',
            'nepromovat' => 'Nepromovat',
            default => $this->status,
        };
    }
}
