<?php

namespace App\Models;

use Cviebrock\EloquentSluggable\Sluggable;
use Cviebrock\EloquentSluggable\SluggableScopeHelpers;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class CompanySchedule extends Model
{
    use HasFactory;

    use Sluggable;
    use SluggableScopeHelpers;

    protected $fillable = [
        'from_year_id',
        'to_year_id',
        'date_from',
        'date_to',
        'desc_ar',
        'desc_en',
        'user_id',
        'photo',
    ];

    // get name translation
    public function getDescAttribute()
    {
        return $this->attributes['desc_' . app()->getLocale()];
    } // end getNameAttribute


    protected $dates = ['date_from', 'date_to'];

    public function keywords()
    {
        return $this->morphMany(KeyWord::class, 'keywordable');
    }

    public function fromschedule()
    {
        return $this->belongsTo(ScheduleYear::class, 'from_year_id', 'id');
    }

    public function toschedule()
    {
        return $this->belongsTo(ScheduleYear::class, 'to_year_id', 'id');
    }

    public function sluggable(): array
    {
        return [
            'slug' => [
                'source' => 'date',
                'onUpdate' => true,
            ]
        ];
    }
}
