<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Warehouse extends Model
{
    protected $table = 'warehouses';
    
    protected $fillable = [
        'warehouse_code',
        'name',
        'address',
        'phone',
        'email',
        'manager_id',
        'capacity',
        'status',
        'notes',
        'created_by',
        'updated_by'
    ];

    // Relationships
    public function manager()
    {
        return $this->belongsTo(User::class, 'manager_id');
    }

    public function productStocks()
    {
        return $this->hasMany(ProductStock::class);
    }

    public function createdBy()
    {
        return $this->belongsTo(User::class, 'created_by');
    }

    public function updatedBy()
    {
        return $this->belongsTo(User::class, 'updated_by');
    }

    // Scopes
    public function scopeActive($query)
    {
        return $query->where('status', 'active');
    }
}