<?php

namespace App;

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

class DocumentationType extends Model
{
    use SoftDeletes;

    public static function withDescription($documentationTypeId = null)
    {
        $query = self::join('documentation_type_descriptions as dtDesc', 'dtDesc.documentation_type_id', 'documentation_types.id')
            ->where('dtDesc.language_id', currentLanguage()->id);

        if ($documentationTypeId){
            $query->where('documentation_types.id', $documentationTypeId);
        }

            $query->select([
            'documentation_types.id',
            'dtDesc.name',
        ]);
        return $documentationTypeId ? $query->first() : $query->cursor() ?? [];
    }

}
