<?php

namespace App\Models;

use App\Services\Upload\FileService;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\SoftDeletes;

class Banner extends Model
{
    //use soft delete
    use SoftDeletes;

    protected $fillable = [
        'status','video','link','file'
    ];

    public function setVideoAttribute($value)
    {
        if($value)
        {
            $video = FileService::uploadVideo($value);
            $this->attributes['video'] = $video;
        }
        else
        {
            $this->attributes['video'] = $this->video;
        }
    }

    public function getVideoShowAttribute()
    {
        if ($this->status == 'link')
        {
            $video = $this->link;
        }
        else
        {
            $video = asset($this->{$this->status});
        }
        return $video;
    }
    /**
     * Get current description of the the Room
     * @return HasOne
     */
    public function currentDescription() :HasOne
    {
        return $this->hasOne(BannerDescription::class)->where('language_id', currentLanguage()->id);
    }
}
