<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class ProductVariant extends Model
{
    protected $fillable = [
        'product_id', 'name_en', 'name_ur', 'sku',
        'price', 'discount_price', 'stock_quantity',
        'is_active', 'sort_order',
    ];

    protected function casts(): array
    {
        return [
            'price'          => 'decimal:2',
            'discount_price' => 'decimal:2',
            'is_active'      => 'boolean',
        ];
    }

    public function product()
    {
        return $this->belongsTo(Product::class);
    }

    public function getEffectivePrice(): float
    {
        return (float) ($this->discount_price ?? $this->price);
    }
}
