<?php

namespace App\Models;

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

class Product extends Model
{
    protected $fillable = ['category_id', 'sku', 'name', 'description', 'unit', 'cost_price', 'retail_price', 'wholesale_price', 'stock_quantity', 'low_stock_at', 'is_active'];
    protected function casts(): array { return ['is_active' => 'boolean', 'cost_price' => 'decimal:2', 'retail_price' => 'decimal:2', 'wholesale_price' => 'decimal:2', 'stock_quantity' => 'decimal:2']; }
    public function category(): BelongsTo { return $this->belongsTo(Category::class); }
    public function movements(): HasMany { return $this->hasMany(StockMovement::class); }
    public function priceFor(string $saleType): float { return (float) ($saleType === 'wholesale' ? $this->wholesale_price : $this->retail_price); }
}
