<?php

namespace App\Models;

use App\Models\BaseModel;

class ItemSerialNumber extends BaseModel
{
    protected $table = 'item_serial_numbers';

    protected $fillable = [
        'company_id','item_id','warehouse_id','serial_number',
        'status','warranty_expiry','source_voucher_type','source_voucher_id',
    ];

    protected $casts = [
        'warranty_expiry' => 'date',
    ];

    public function company()   { return $this->belongsTo(Company::class); }
    public function item()      { return $this->belongsTo(Item::class); }
    public function warehouse() { return $this->belongsTo(Warehouse::class); }

    public function scopeInStock($q)   { return $q->where('status', 'in_stock'); }
    public function scopeByItem($q, int $itemId) { return $q->where('item_id', $itemId); }
}
