<?php

namespace App\Domain\POS\Models;

use App\Domain\POS\Enums\POSPaymentMethod;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use App\Domain\Shared\Traits\ScopedThroughBranch;

class POSSplitPayment extends Model
{
    use ScopedThroughBranch;

    /**
     * The parent whose branch this row inherits. A line item has no
     * branch of its own and must not grow one — a denormalised copy
     * here is a second source of truth that drifts the first time the
     * parent moves.
     */
    protected static string $branchScopeRelation = 'transaction';

    protected $table = 'pos_split_payments';

    protected $fillable = [
        'pos_transaction_id',
        'payment_method',
        'amount',
        'reference',
    ];

    protected $casts = [
        'payment_method' => POSPaymentMethod::class,
        'amount' => 'integer',
    ];

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