<?php

declare(strict_types=1);

namespace App\Models;

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

class DberpInventoryBatchMovement extends Model
{
    protected $table = 'dberp_inventory_batch_movements';

    /**
     * @var list<string>
     */
    protected $fillable = [
        'batch_id',
        'product_id',
        'warehouse_id',
        'direction',
        'change_quantity',
        'before_quantity',
        'after_quantity',
        'business_type',
        'business_number',
        'source_type',
        'source_id',
        'business_time',
        'remark',
    ];

    protected function casts(): array
    {
        return [
            'batch_id' => 'integer',
            'product_id' => 'integer',
            'warehouse_id' => 'integer',
            'change_quantity' => 'decimal:4',
            'before_quantity' => 'decimal:4',
            'after_quantity' => 'decimal:4',
            'source_id' => 'integer',
            'business_time' => 'datetime',
        ];
    }

    public function batch(): BelongsTo
    {
        return $this->belongsTo(DberpInventoryBatch::class, 'batch_id');
    }

    public function product(): BelongsTo
    {
        return $this->belongsTo(DberpProduct::class, 'product_id');
    }

    public function warehouse(): BelongsTo
    {
        return $this->belongsTo(DberpWarehouse::class, 'warehouse_id');
    }
}