<?php

namespace App\Models;

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

class PwShopLog extends Model
{
    /**
     * The table associated with the model.
     */
    protected $table = 'pw_shop_logs';

    /**
     * The attributes that are mass assignable.
     */
    protected $fillable = [
        'shop_item_id',
        'user_id',
        'quantity',
        'total_price',
        'item_data',
    ];

    /**
     * The attributes that should be cast.
     */
    protected $casts = [
        'shop_item_id' => 'integer',
        'user_id' => 'integer',
        'quantity' => 'integer',
        'total_price' => 'integer',
        'item_data' => 'array',
    ];

    /**
     * Get the shop item that was purchased.
     */
    public function shopItem(): BelongsTo
    {
        return $this->belongsTo(PwShop::class, 'shop_item_id');
    }

    /**
     * Get the user who made the purchase.
     */
    public function user(): BelongsTo
    {
        return $this->belongsTo(User::class);
    }
}
