<?php

namespace App\Models;

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

class Service extends Model
{
    //
    use SoftDeletes;
    protected $fillable = [
        'id'
    ];

    public static function withDescription($service_id = null)
    {
        $query = self::orderByDesc('services.id')->join('service_descriptions as cd', 'cd.service_id', 'services.id')
            ->where('cd.language_id', currentLanguage()->id)
            ->select(['services.created_at', 'cd.*']);

        if ($service_id)
        {
            if (is_array($service_id))
            {
                $query->whereIn('services.id', $service_id);
            }
            else
            {
                $query->where('services.id', $service_id);
            }
        }

        $query->select([
            'services.*',
            'cd.name',
        ]);
        return $query;
    }
    public function currentDescription()
    {
        return $this->hasOne(ServiceDescription::class)->where('language_id',currentLanguage()['id']);
    }
}
