<?php

namespace App\Models;

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

final class PwShop extends Model
{
    /**
     * The table associated with the model.
     */
    protected $table = 'pw_shop';

    /**
     * The attributes that are mass assignable.
     * Note: item_name, description, item_color are dynamically loaded from RAE file via ItemDataService
     */
    protected $fillable = [
        'item_id',
        'count',
        'octet',
        'mask',
        'proctype',
        'price',
        'is_active',
    ];

    /**
     * The attributes that should be cast.
     */
    protected $casts = [
        'item_id' => 'integer',
        'count' => 'integer',
        'mask' => 'integer',
        'proctype' => 'integer',
        'price' => 'integer',
        'is_active' => 'boolean',
    ];

    /**
     * Get the purchase logs for this shop item.
     */
    public function logs(): HasMany
    {
        return $this->hasMany(PwShopLog::class, 'shop_item_id');
    }

    public function scopeActive(Builder $query): Builder
    {
        return $query->where('is_active', true);
    }
}
