<?php

namespace App\Domain\POS\Models;

use App\Domain\POS\Enums\POSItemType;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class POSTransactionItem extends Model
{
    protected $table = 'pos_transaction_items';

    protected $fillable = [
        'pos_transaction_id',
        'item_type',
        'item_id',
        'item_name_ar',
        'quantity',
        'unit_price',
        'discount_amount',
        'line_total',
        'pricing_snapshot',
        'metadata',
    ];

    protected $casts = [
        'item_type' => POSItemType::class,
        'quantity' => 'integer',
        'unit_price' => 'integer',
        'discount_amount' => 'integer',
        'line_total' => 'integer',
        'pricing_snapshot' => 'array',
        'metadata' => 'array',
    ];

    public function transaction(): BelongsTo
    {
        return $this->belongsTo(POSTransaction::class, 'pos_transaction_id');
    }
}
