<?php

namespace App\Models\Game\Player;

use App\Models\Enums\ApplyTypesEnum;
use App\Models\Enums\ItemTypesEnum;
use App\Models\Enums\LimitTypesEnum;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;

/**
 * @property int $vnum
 * @property string $name
 * @property string $locale_name
 * @property ItemTypesEnum $type
 * @property int $subtype
 * @property int|null $weight
 * @property int|null $size
 * @property int|null $antiflag
 * @property int|null $flag
 * @property int|null $wearflag
 * @property string $immuneflag
 * @property int|null $gold
 * @property int $shop_buy_price
 * @property int $refined_vnum
 * @property int $refine_set
 * @property int $refine_set2
 * @property int $magic_pct
 * @property LimitTypesEnum|null $limittype0
 * @property int|null $limitvalue0
 * @property LimitTypesEnum|null $limittype1
 * @property int|null $limitvalue1
 * @property ApplyTypesEnum|null $applytype0
 * @property int|null $applyvalue0
 * @property ApplyTypesEnum|null $applytype1
 * @property int|null $applyvalue1
 * @property ApplyTypesEnum|null $applytype2
 * @property int|null $applyvalue2
 * @property int|null $value0
 * @property int|null $value1
 * @property int|null $value2
 * @property int|null $value3
 * @property int|null $value4
 * @property int|null $value5
 * @property int|null $socket0
 * @property int|null $socket1
 * @property int|null $socket2
 * @property int|null $socket3
 * @property int|null $socket4
 * @property int|null $socket5
 * @property int $specular
 * @property int $socket_pct
 * @property int $addon_type
 * @property-read \App\Models\Game\Player\RefineProto|null $refineSet
 *
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ItemProto newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ItemProto newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ItemProto query()
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ItemProto whereAddonType($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ItemProto whereAntiflag($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ItemProto whereApplytype0($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ItemProto whereApplytype1($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ItemProto whereApplytype2($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ItemProto whereApplyvalue0($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ItemProto whereApplyvalue1($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ItemProto whereApplyvalue2($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ItemProto whereFlag($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ItemProto whereGold($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ItemProto whereImmuneflag($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ItemProto whereLimittype0($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ItemProto whereLimittype1($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ItemProto whereLimitvalue0($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ItemProto whereLimitvalue1($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ItemProto whereLocaleName($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ItemProto whereMagicPct($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ItemProto whereName($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ItemProto whereRefineSet($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ItemProto whereRefineSet2($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ItemProto whereRefinedVnum($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ItemProto whereShopBuyPrice($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ItemProto whereSize($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ItemProto whereSocket0($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ItemProto whereSocket1($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ItemProto whereSocket2($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ItemProto whereSocket3($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ItemProto whereSocket4($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ItemProto whereSocket5($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ItemProto whereSocketPct($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ItemProto whereSpecular($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ItemProto whereSubtype($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ItemProto whereType($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ItemProto whereValue0($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ItemProto whereValue1($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ItemProto whereValue2($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ItemProto whereValue3($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ItemProto whereValue4($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ItemProto whereValue5($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ItemProto whereVnum($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ItemProto whereWearflag($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ItemProto whereWeight($value)
 *
 * @mixin \Eloquent
 */
class ItemProto extends Model
{
    /**
     * Indicates if the model should be timestamped.
     *
     * @var bool
     */
    public $timestamps = false;

    /**
     * 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',
    ];

    /**
     * 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 = [
        'type' => ItemTypesEnum::class,
        'limittype0' => LimitTypesEnum::class,
        'limittype1' => LimitTypesEnum::class,
        'applytype0' => ApplyTypesEnum::class,
        'applytype1' => ApplyTypesEnum::class,
        'applytype2' => ApplyTypesEnum::class,
    ];

    public function refineSet(): BelongsTo
    {
        return $this->belongsTo(RefineProto::class, 'refine_set');
    }

    public function sellers(): BelongsToMany
    {
        return $this->belongsToMany(
            Shop::class,
            ShopItem::class,
            'item_vnum',
            'shop_vnum',
            'vnum',
            'vnum'
        )
            ->where('npc_vnum', '!=', 0)
            ->withPivot('count');
    }
}
