<?php

namespace App\Models;

use App\Models\Backoffice\Support\TranslationModel;

class DepartmentLanguage extends TranslationModel
{
    public function department()
    {
        return $this->belongsTo(Department::class);
    }

    public function generateFullName()
    {
        $department = $this->department;
        $fullNameParts = [];
        do {
            $fullNameParts[] = $department->languages->where('language_id', $this->language_id)->first()->title;
            $parentWebsiteObject = $department->websites[0]->parent;
            $department = $parentWebsiteObject ? $parentWebsiteObject->objectable : null;
        } while ($department);
        $this->full_name = implode(' → ', array_reverse($fullNameParts));
    }
}
