<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class ProductUnit extends Model
{
    protected $fillable = [
        'product_id', 'unit_id', 'conversion_factor',
        'is_base_unit', 'is_purchase_unit', 'is_sales_unit',
        'barcode', 'purchase_price', 'selling_price', 'wholesale_price',
    ];

    protected $casts = [
        'conversion_factor' => 'decimal:4',
        'purchase_price'    => 'decimal:2',
        'selling_price'     => 'decimal:2',
        'wholesale_price'   => 'decimal:2',
        'is_base_unit'      => 'boolean',
        'is_purchase_unit'  => 'boolean',
        'is_sales_unit'     => 'boolean',
    ];

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

    public function unit()
    {
        return $this->belongsTo(Unit::class);
    }
}
