<?php

namespace App;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * Class CaseRequest
 * @mixin Builder
 * @package App
 */
class CaseRequest extends Model
{
    use SoftDeletes;

    protected $fillable = [
        'user_id',
        'case_topic_id',
        'name',
        'email',
        'phone',
        'request_type',
        'subject',
        'details',
        'requests',
        'request_files',
    ];

    protected $casts = ['request_files' => 'array'];

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

    public function caseUpdates()
    {
        return $this->hasMany(CaseUpdate::class)
            ->join('case_update_descriptions as cud', 'cud.case_update_id', 'case_updates.id')
            ->where('cud.language_id', currentLanguage()->id)
            ->select(['case_updates.*', 'cud.file_name']);
    }
}
