<?php

namespace App\Models;

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

class SurveyQuestion extends Model
{
    use HasFactory;

    protected $fillable = [
        'survey_id',
        'question_en',
        'question_ar',
        'type',
        'options_en',
        'options_ar',
        'rating_min',
        'rating_max',
        'is_required',
        'sort_order',
    ];

    protected $casts = [
        'options_en'  => 'array',
        'options_ar'  => 'array',
        'is_required' => 'boolean',
        'rating_min'  => 'integer',
        'rating_max'  => 'integer',
        'sort_order'  => 'integer',
    ];

    public function getQuestionAttribute(): string
    {
        return app()->getLocale() === 'ar'
            ? ($this->question_ar ?? $this->question_en)
            : $this->question_en;
    }

    public function getOptionsAttribute(): ?array
    {
        return app()->getLocale() === 'ar'
            ? ($this->options_ar ?? $this->options_en)
            : $this->options_en;
    }

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