<?php

namespace App\Models;

use Database\Factories\LanguageFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;

class Language extends Model
{
    /** @use HasFactory<LanguageFactory> */
    use HasFactory;

    protected $fillable = [
        'short_code',
        'name',
        'native_name',
        'is_active',
    ];

    protected $casts = [
        'is_active' => 'boolean',
    ];

    /**
     * @return BelongsToMany<PlatformInstance, $this>
     */
    public function platformInstances(): BelongsToMany
    {
        return $this->belongsToMany(PlatformInstance::class)
            ->withPivot(['platform_language_id', 'is_default'])
            ->withTimestamps();
    }

    /**
     * @return HasMany<PlatformChannel, $this>
     */
    public function platformChannels(): HasMany
    {
        return $this->hasMany(PlatformChannel::class);
    }

    /**
     * @return HasMany<Feed, $this>
     */
    public function feeds(): HasMany
    {
        return $this->hasMany(Feed::class);
    }
}
