<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class InventoryMovement extends Model
{
    use HasFactory;

    protected $fillable = [
        'user_id',
        'date',
        'item_id',
        'type',
        'quantity',
        'reason',
        'ref_json',
    ];

    protected $casts = [
        'date' => 'date:Y-m-d',
        'quantity' => 'float',
        'ref_json' => 'array',
    ];

    protected $hidden = [
        'ref_json',
    ];

    protected $appends = [
        'ref',
    ];

    public function getRefAttribute(): array
    {
        return is_array($this->ref_json) ? $this->ref_json : [];
    }
}
