<?php

namespace App\Models;

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

class Product extends Model
{
    use HasFactory;

    /**
     * @var array<int, string>
     */
    protected $fillable = [
        'category_id',
        'subcategory_id',
        'sku',
        'hsn_code',
        'name',
        'slug',
        'description',
        'dp_price',
        'mrp',
        'bv',
        'gst_percent',
        'stock',
        'is_active',
        'image_path',
        'is_digital',
        'tax_rule_id',
        'created_by',
    ];

    /**
     * @var array<string, string>
     */
    protected $casts = [
        'dp_price' => 'decimal:2',
        'mrp' => 'decimal:2',
        'bv' => 'decimal:2',
        'gst_percent' => 'decimal:2',
        'is_active' => 'boolean',
        'is_digital' => 'boolean',
    ];

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

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

    public function images(): HasMany
    {
        return $this->hasMany(ProductImage::class);
    }
}
