<?php

namespace App\Models\Ecommerce\Product\Inventory;

use App\Models\Concerns\HasSchemalessAttributes;
use App\Models\Ecommerce\Channel\Channel;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

class InventoryHistory extends Model
{
    use HasFactory;
    use HasSchemalessAttributes;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'date',
        'inventory_id',
        'channel_id',
        'notes',
        'total',
        'options',
    ];

    /**
     * Attributes that are casted
     */
    protected $casts = [
        'date' => 'date',
    ];

    /**
     * Channel
     */
    public function channel(): BelongsTo
    {
        return $this->belongsTo(Channel::class);
    }

    /**
     * Inventory
     */
    public function inventory(): BelongsTo
    {
        return $this->belongsTo(Inventory::class);
    }

    /**
     * Items
     */
    public function items(): HasMany
    {
        return $this->hasMany(InventoryHistoryItem::class, 'inventory_history_id');
    }
}
