<?php

namespace App\Models;

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

/**
 * Producto de inventario (almacén). No confundir con App\Models\Producto (lavandería/POS).
 */
class InventoryProduct extends Model
{
    use SoftDeletes;

    protected $table = 'inventory_products';

    protected $fillable = [
        'sku',
        'name',
        'product_type_id',
        'brand_id',
        'category_id',
        'subcategory_id',
        'supplier_id',
        'stock_quantity',
        'min_stock',
        'active',
    ];

    protected $casts = [
        'stock_quantity' => 'string',
        'min_stock' => 'decimal:4',
        'active' => 'boolean',
    ];

    public function productType(): BelongsTo
    {
        return $this->belongsTo(InventoryProductType::class, 'product_type_id');
    }

    public function brand(): BelongsTo
    {
        return $this->belongsTo(InventoryBrand::class, 'brand_id');
    }

    public function category(): BelongsTo
    {
        return $this->belongsTo(InventoryCategory::class, 'category_id');
    }

    public function subcategory(): BelongsTo
    {
        return $this->belongsTo(InventorySubcategory::class, 'subcategory_id');
    }

    public function supplier(): BelongsTo
    {
        return $this->belongsTo(InventorySupplier::class, 'supplier_id');
    }

    public function movements(): HasMany
    {
        return $this->hasMany(InventoryMovement::class, 'inventory_product_id');
    }

    public function inventoryTransferLines(): HasMany
    {
        return $this->hasMany(InventoryTransferLine::class, 'inventory_product_id');
    }
}
