<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * @property mixed doctor_ids
 */
class Career extends Model
{
    use SoftDeletes;

    protected $fillable = ['service_id',];


    public function careerApplications()
    {
        return $this->hasMany(CareerApplication::class);
    }

    /**
     * Get description for pages
     * @return HasMany
     */
    public function descriptions() :HasMany
    {
        return $this->hasMany(CareerDescription::class);
    }

    /**
     * Get description of current language for pages
     * @return HasOne
     */
    public function currentDescription() :HasOne
    {
        return $this->hasOne(CareerDescription::class)->where('language_id', currentLanguage()->id);
    }


    public static function withDescription()
    {
        $query = self::join('career_descriptions as cDesc', 'cDesc.career_id', 'careers.id')
            ->where('cDesc.language_id', currentLanguage()->id)
            ->select(['careers.id', 'careers.service_id', 'cDesc.name', 'cDesc.description']);

        return $query->cursor();
    }


}
