<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;

class ResultsCompilation extends Model
{
    use SoftDeletes;

    protected $fillable = [
        'student_id',
        'class_id',
        'term_id',
        'subject_id',
        'total_score',
        'average_score',
        'grade_letter',
        'class_position',
        'status',
        'submitted_by',
        'submitted_at',
        'approved_by',
        'approved_at',
        'released_by',
        'released_at',
        'rejection_reason',
        'teacher_remarks',
    ];

    protected function casts(): array
    {
        return [
            'total_score' => 'decimal:2',
            'average_score' => 'decimal:2',
            'submitted_at' => 'datetime',
            'approved_at' => 'datetime',
            'released_at' => 'datetime',
        ];
    }

    public function student(): BelongsTo
    {
        return $this->belongsTo(Student::class);
    }

    public function schoolClass(): BelongsTo
    {
        return $this->belongsTo(SchoolClass::class, 'class_id');
    }

    public function term(): BelongsTo
    {
        return $this->belongsTo(Term::class);
    }

    public function subject(): BelongsTo
    {
        return $this->belongsTo(Subject::class);
    }
}
