<?php

namespace Daylight\Core\Models;

use Daylight\Core\Models\Enums\PublishStatus;
use Daylight\Core\Modules\Multilingualism\Contracts\HasTranslations;
use Daylight\Core\Modules\Multilingualism\Models\Concerns\InteractsWithTranslations;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;

class Label extends Model implements HasTranslations
{
    use InteractsWithTranslations;

    protected $guarded = [];

    protected function casts(): array
    {
        return [
            'status' => PublishStatus::class,
        ];
    }

    public function translatedFields(): array
    {
        return ['name'];
    }

    public function translations(): HasMany
    {
        return $this->hasMany(daylightModel('label_translation'));
    }

    public function defaultTranslation(): HasOne
    {
        return $this->hasOne(daylightModel('label_translation'))
            ->where('locale', config('multilingualism.default_locale'));
    }
}
