<?php

namespace App\Models\Mall;

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

class MallCategory extends Model
{
    /**
     * Indicates if the model should be timestamped.
     *
     * @var bool
     */
    public $timestamps = false;

    /**
     * The connection name for the model.
     *
     * @var string|null
     */
    protected $connection = 'website';

    /**
     * The attributes that are mass assignable.
     *
     * @var array<int, string>
     */
    protected $fillable = [
        'name',
    ];

    /**
     * The attributes that should be hidden for serialization.
     *
     * @var array<int, string>
     */
    protected $hidden = [

    ];

    /**
     * The attributes that should be cast.
     *
     * @var array<string, string>
     */
    protected $casts = [

    ];

    /**
     * Get the items in this category
     *
     * @return HasMany
     */
    public function items(): HasMany
    {
        return $this->hasMany(MallItem::class, 'category_id', 'id');
    }

    /**
     * Get translated category name
     *
     * @return string
     */
    public function getTranslatedNameAttribute(): string
    {
        $key = 'mall/main.category.' . $this->id;
        $translation = __($key);

        // If translation doesn't exist, fall back to original name
        return $translation === $key ? $this->name : $translation;
    }
}
