<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\MorphTo;

class StatementTransactionOwner extends Model
{
    use HasFactory;

    protected $fillable = [
        'statement_transaction_id',
        'type',
        'system',
        'owner_type',
        'owner_id',
        'owner_reference',
        'invoice_reference',
        'receipt_reference',
        'status',
    ];
    
    public function owner(): morphTo
    {
        return $this->morphTo();
    }

    public function transaction(): BelongsTo
    {
        return $this->belongsTo(StatementTransaction::class, 'statement_transaction_id', 'id');
    }

    public function scopeGetSiblingsOwner($query) {
        $query->where('system', $this->system)
        ->where('owner_type', $this->owner_type)
        ->where('owner_id', $this->owner_id);
    }
}
