<?php

namespace App;

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

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

    protected $fillable = ['image', 'civil_engineers_no', 'architects_engineers_no', 'general_engineers_no'];

    public static function withDescription($ids = [], $skip = null)
    {
        $query = self::orderByDesc('gucs.id')
            ->join('guc_descriptions as gDesc', 'gDesc.guc_id', 'gucs.id')
            ->where('gDesc.language_id', currentLanguage()->id)
            ->limit(6)
            ->select(['gDesc.title', 'gDesc.description', 'gucs.*']);

        if (count($ids) > 1){
            $query->whereIn('gucs.id', $ids);
        }
        if (count($ids) == 1){
            $query->where('gucs.id', $ids);
        }

        if ($skip){
            $query->skip($skip)->take(6);
        }


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


}
