<?php

namespace App;

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

class Slider extends Model
{
    use SoftDeletes;

    protected $fillable = [
        'show_in',
        'image',
    ];


    public static function withDescription($showIn = 'home', $ids = [], $notIn = [])
    {
        $query = self::join('slider_descriptions as sliderDesc', 'sliderDesc.slider_id', 'sliders.id')
            ->where('sliderDesc.language_id', currentLanguage()->id);

        if (count($ids)){
            $query->whereIn('sliders.id', $ids);
        }

        if (count($notIn)){
            $query->whereNotIn('sliders.id', $notIn);
        }

        if ($showIn){
            $query->where('sliders.show_in', $showIn);
        }
        $query->select(['sliders.image', 'sliderDesc.title',  'sliderDesc.description']);

        return count($ids) == 1 ? $query->first() : $query->get();
    }

}
