<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class IftaQuestion extends Model
{
    protected $fillable = [
        'user_id',
        'locale',
        'category',
        'title',
        'body',
        'status',
        'is_approved',
        'answered_at',
        'approved_at',
        'approved_by',
    ];

    protected function casts(): array
    {
        return [
            'is_approved' => 'boolean',
            'answered_at' => 'datetime',
            'approved_at' => 'datetime',
        ];
    }

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

    public function replies()
    {
        return $this->hasMany(IftaReply::class);
    }

    public function officialReplies()
    {
        return $this->hasMany(IftaReply::class)->where('is_official', true)->latest();
    }

    public function approver()
    {
        return $this->belongsTo(User::class, 'approved_by');
    }
}
