<?php

declare(strict_types=1);

namespace App\Models;

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

class DberpInventorySerialNumberLog extends Model
{
    protected $table = 'dberp_inventory_serial_number_logs';

    /**
     * @var list<string>
     */
    protected $fillable = [
        'serial_number_id',
        'product_id',
        'warehouse_id',
        'batch_id',
        'previous_status',
        'current_status',
        'business_type',
        'business_number',
        'source_type',
        'source_id',
        'business_time',
        'context_snapshot',
        'remark',
    ];

    protected function casts(): array
    {
        return [
            'serial_number_id' => 'integer',
            'product_id' => 'integer',
            'warehouse_id' => 'integer',
            'batch_id' => 'integer',
            'source_id' => 'integer',
            'business_time' => 'datetime',
            'context_snapshot' => 'array',
        ];
    }

    public function serialNumber(): BelongsTo
    {
        return $this->belongsTo(DberpInventorySerialNumber::class, 'serial_number_id');
    }

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

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

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