<?php

namespace App\Modules\Inventory\Models;

use App\Modules\Admin\Tenancy\Traits\BelongsToTenant;
use App\Modules\Inventory\Support\InventoryLifecycleState;
use App\Modules\Inventory\Support\InventoryUserStamp;
use App\Modules\Inventory\Support\LogsInventoryCatalogActivity;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;

class Warehouse extends Model
{
    use BelongsToTenant;
    use InventoryUserStamp;
    use LogsInventoryCatalogActivity;

    protected $table = 'inventory_warehouses';

    protected $fillable = [
        'tenant_id',
        'code',
        'name',
        'address',
        'is_active',
        'lifecycle_state',
        'deactivated_at',
        'created_by',
        'updated_by',
    ];

    protected function casts(): array
    {
        return [
            'address' => 'array',
            'is_active' => 'boolean',
            'lifecycle_state' => InventoryLifecycleState::class,
            'deactivated_at' => 'datetime',
        ];
    }

    public function sections(): HasMany
    {
        return $this->hasMany(WarehouseSection::class, 'warehouse_id');
    }
}
