<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Product extends Model
{
    protected $fillable = [
        'seller_id', 
        'category_id', 
        'subcategory_id', 
        'title', 
        'slug', 
        'description', 
        'currency_code',  
        'price', 
        'original_price', 
        'stock', 
        'moq',
        'shipping_time', 
        'delivery_via', 
        'refund_policy', 
        'customization_options', 
        'specifications',
        'variations',
        'coupon_code', 
        'discount_percentage', 
        'max_discount_percentage',
        'min_order_amount_for_discount',
        'original_min_order_amount',
        'is_free_shipping', 
        'shipping_charge',
        'original_shipping_charge',
        'shipping_charge_type',
        'views_count',
        'is_featured'
    ];

    protected $casts = [
        'customization_options' => 'array',
        'specifications' => 'array',
        'variations' => 'array',
        'is_free_shipping' => 'boolean',
        'is_featured' => 'boolean',
    ];

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

    public function seller()
    {
        return $this->belongsTo(User::class, 'seller_id');
    }

    public function category()
    {
        return $this->belongsTo(Category::class);
    }

    public function reviews()
    {
        return $this->hasMany(Review::class);
    }

    public function orderItems()
    {
        return $this->hasMany(OrderItem::class, 'product_id');
    }
}