<?php

declare(strict_types=1);

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

class MediaCategory extends Model
{
    protected $guarded = ['id', 'created_at', 'updated_at'];

    public const TYPE_GALLERY = 'gallery';
    public const TYPE_DOCUMENT = 'document';

    public function parent(): BelongsTo
    {
        return $this->belongsTo(MediaCategory::class, 'parent_id');
    }

    public function children(): HasMany
    {
        return $this->hasMany(MediaCategory::class, 'parent_id')->orderBy('sort_order');
    }

    public function mediaItems(): HasMany
    {
        return $this->hasMany(MediaItem::class, 'category_id');
    }

    public static function typeOptions(): array
    {
        return [
            self::TYPE_GALLERY => 'گالری',
            self::TYPE_DOCUMENT => 'اسناد',
        ];
    }
}
