<?php

declare(strict_types=1);

namespace App\Models;

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

final class Session extends Model
{
    use HasFactory;

    protected $table = 'questionnaire_sessions';

    /**
     * Fillable attributes for mass assignment.
     */
    protected $fillable = [
        'user_id',
        'category_id',
        'screening_id',
        'status',
        'score',
        'result',
        'additional_comments',
        'completed_at',
    ];

    /**
     * Cast attributes to specific types.
     */
    protected function casts(): array
    {
        return [
            'user_id' => 'integer',
            'category_id' => 'integer',
            'screening_id' => 'integer',
            'score' => 'integer',
            'completed_at' => 'datetime',
        ];
    }

    /**
     * Get the user that owns this session.
     */
    public function user(): BelongsTo
    {
        return $this->belongsTo(User::class);
    }

    /**
     * Get the category for this session.
     */
    public function category(): BelongsTo
    {
        return $this->belongsTo(Category::class);
    }

    /**
     * Get the screening that preceded this session.
     */
    public function screening(): BelongsTo
    {
        return $this->belongsTo(Screening::class);
    }

    /**
     * Get all answers for this session.
     */
    public function answers(): HasMany
    {
        return $this->hasMany(Answer::class);
    }

    /**
     * Get all logs for this session.
     */
    public function logs(): HasMany
    {
        return $this->hasMany(Log::class);
    }
}
