<?php

namespace App\Models;

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

class Product extends Model
{
    use HasUlids, SoftDeletes;

    protected $fillable = [
        'user_id', 'store_id', 'local_id',
        'type', // [INTEGRATION] product|service|bundle
        'name', 'barcode', 'category_id',
        'description', 'cost_price', 'avg_cost', // [INTEGRATION]
        'sell_price', 'stock',
        'track_stock', 'has_variants', 'track_batches', // [INTEGRATION]
        'expiry_date', // [INTEGRATION]
        'low_stock_threshold', 'reorder_point', 'preferred_supplier_id',
        'image_path', 'image_hash',
        'unit', 'tax_id', 'tax_ids', // [INTEGRATION]
        'is_active', 'device_id', 'sync_version', 'is_deleted',
    ];

    protected $casts = [
        'cost_price' => 'float',
        'avg_cost' => 'float', // [INTEGRATION]
        'sell_price' => 'float',
        'stock' => 'float',
        'low_stock_threshold' => 'float',
        'reorder_point' => 'float',
        'track_stock' => 'boolean', // [INTEGRATION]
        'has_variants' => 'boolean', // [INTEGRATION]
        'track_batches' => 'boolean', // [INTEGRATION]
        'expiry_date' => 'date', // [INTEGRATION]
        'is_active' => 'boolean',
        'is_deleted' => 'boolean',
        'sync_version' => 'integer',
    ];

    public function user(): BelongsTo
    {
        return $this->belongsTo(User::class);
    }

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