<?php

namespace App\Models;

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

class SituatieScolara extends Model
{
    protected $table = 'situatii_scolare';

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

    protected $fillable = [
        'elev_id',
        'perioada_id',
        'media_generala',
        'nota_purtare',
        'status',
        'total_absente',
        'absente_nemotivate',
        'nr_corigente',
        'observatii',
        'incheiat',
        'incheiat_de',
        'incheiat_la',
    ];

    protected $casts = [
        'media_generala' => 'decimal:2',
        'incheiat' => 'boolean',
        'incheiat_la' => 'datetime',
    ];

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

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

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

    public function getStatusLabelAttribute(): string
    {
        return match ($this->status) {
            'promovat' => 'Promovat',
            'corigent' => 'Corigent',
            'repetent' => 'Repetent',
            'amanat' => 'Amânat',
            'in_curs' => 'În curs',
            default => $this->status,
        };
    }
}
