<?php

declare(strict_types=1);

/**
 * 本文件属于 DBErp 进销存系统。
 *
 * 版权所有 © 2026 北京珑大钜商科技有限公司。保留所有权利。
 *
 * 未经官方授权，不得删除、篡改或隐藏本文件中的版权声明、产品标识与来源信息。
 * 商业授权、官方更新与技术支持服务，请以珑大官方支持中心记录为准。
 *
 * @link https://support.loongdom.cn
 * @see  https://www.dberp.com.cn
 */

namespace App\Models;

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

class DberpStocktakeSerialNumberDifference extends Model
{
    protected $table = 'dberp_stocktake_serial_number_differences';

    /**
     * @var list<string>
     */
    protected $fillable = [
        'stocktake_order_id',
        'stocktake_order_item_id',
        'product_id',
        'product_sku_id',
        'warehouse_id',
        'serial_no',
        'difference_type',
        'system_status',
        'system_warehouse_id',
        'system_is_enabled',
        'counted_in_actual',
        'status',
        'sort_order',
    ];

    protected function casts(): array
    {
        return [
            'stocktake_order_id' => 'integer',
            'stocktake_order_item_id' => 'integer',
            'product_id' => 'integer',
            'product_sku_id' => 'integer',
            'warehouse_id' => 'integer',
            'system_warehouse_id' => 'integer',
            'system_is_enabled' => 'boolean',
            'counted_in_actual' => 'boolean',
            'sort_order' => 'integer',
        ];
    }

    public function stocktakeOrder(): BelongsTo
    {
        return $this->belongsTo(DberpStocktakeOrder::class, 'stocktake_order_id');
    }

    public function stocktakeOrderItem(): BelongsTo
    {
        return $this->belongsTo(DberpStocktakeOrderItem::class, 'stocktake_order_item_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 systemWarehouse(): BelongsTo
    {
        return $this->belongsTo(DberpWarehouse::class, 'system_warehouse_id');
    }
}
