<?php

namespace App\Models\Game\Player;

use App\Models\Game\Common\Locale;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\App;

class ItemProto 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 = 'player';

    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'item_proto';

    /**
     * The primary key for the model.
     *
     * @var string
     */
    protected $primaryKey = 'vnum';

    /**
     * The attributes that are mass assignable.
     *
     * @var array<int, string>
     */
    protected $fillable = [
        'name', 'locale_name', 'value0', 'value1', 'value2', 'value3', 'value4', 'value5',
        'socket0', 'socket1', 'socket2', 'socket3', 'socket4', 'socket5',
    ];

    /**
     * The attributes that should be appended to the model's array form.
     *
     * @var array
     */
    protected $appends = ['localized_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 item name (returns English name from locale_name field)
     *
     * @return string
     */
    public function getLocalizedNameAttribute(): string
    {
        // Return the locale_name field (English name)
        // The 'name' field contains Korean text in EUC-KR encoding
        return $this->attributes['locale_name'] ?? $this->attributes['name'] ?? 'Unknown Item';
    }
}
