<?php

namespace Modules\SystemCore\App\Models;

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

class CoreProductVariant extends Model
{
    use SoftDeletes;

    protected $table = 'core_product_variants';

    protected $fillable = [
        'product_id',
        'sku',
        'barcode',
        'name',
        'attributes',
        'price',
        'cost_price',
        'stock',
        'is_active',
    ];

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

    /**
     * Get parent product
     */
    public function product(): BelongsTo
    {
        return $this->belongsTo(CoreProduct::class, 'product_id');
    }
}
