<?php

namespace App\Models;

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

class InterviewQuestion extends Model
{
    use SoftDeletes;

    protected $fillable = [
        'category_id',
        'question',
        'option_a',
        'option_b',
        'option_c',
        'option_d',
        'correct_answer',
        'explanation',
        'difficulty',
        'image',
    ];

    protected $casts = [
        'difficulty' => 'integer',
        'deleted_at' => 'datetime',
        'image' => 'string',
    ];

    public function category(): BelongsTo
    {
        return $this->belongsTo(InterviewCategory::class, 'category_id');
    }

    public function scopeByDifficulty($query, $level)
    {
        return $query->where('difficulty', $level);
    }

    public function scopeRandom($query, $count = 10)
    {
        return $query->inRandomOrder()->limit($count);
    }
}
