<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class CaseProgress extends Model
{
    use HasFactory;

    // ── Fillable ───────────────────────────────────────────────
    protected $fillable = [
        'user_id',
        'case_id',
        'status',
        'solution_revealed',
        'completed_at',
        'case_rating',
        'case_rated_at',
    ];

    // ── Casts ─────────────────────────────────────────────────
    protected $casts = [
        'solution_revealed' => 'boolean',
        'completed_at'      => 'datetime',
        'case_rating'       => 'integer',
        'case_rated_at'     => 'datetime',
    ];

    // ── Helpers ───────────────────────────────────────────────

    public function isCompleted(): bool
    {
        return $this->status === 'completed';
    }

    // ── Relationships ─────────────────────────────────────────

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

    public function case(): BelongsTo
    {
        return $this->belongsTo(Cases::class, 'case_id');
    }
}