<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class SaleItem extends Model
{
    protected $fillable = ['sale_id', 'product_id', 'unit_id', 'product_name_en_snapshot', 'product_name_ar_snapshot', 'unit_snapshot', 'conversion_factor', 'quantity', 'base_quantity', 'unit_price', 'gross_amount', 'discount_amount', 'taxable_amount', 'vat_rate_snapshot', 'vat_amount', 'line_total', 'cost_price_snapshot', 'cost_total', 'gross_profit'];
    protected $casts = ['quantity' => 'decimal:4', 'base_quantity' => 'decimal:4', 'conversion_factor' => 'decimal:4', 'unit_price' => 'decimal:2', 'gross_amount' => 'decimal:2', 'discount_amount' => 'decimal:2', 'taxable_amount' => 'decimal:2', 'vat_rate_snapshot' => 'decimal:2', 'vat_amount' => 'decimal:2', 'line_total' => 'decimal:2', 'cost_price_snapshot' => 'decimal:4', 'cost_total' => 'decimal:4', 'gross_profit' => 'decimal:2'];

    public function sale() { return $this->belongsTo(Sale::class); }
    public function product() { return $this->belongsTo(Product::class); }
    public function unit() { return $this->belongsTo(Unit::class); }
    public function salesReturnItems() { return $this->hasMany(SalesReturnItem::class); }
}
