<?php

namespace App\Models;

use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Relations\HasOne;

use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use App\Classes\General\Interfaces\KeyValueInterface;

/**
 * Class Bank
 * @package App\Models
 *
 * @property int $country_id
 * @property int $company_id
 * @property string $bank_name
 * @property string $holder_name
 * @property string $account_no
 * @property int $type
 * @property int $default
 * @property int $status
 */
class Bank extends AbstractModel implements KeyValueInterface
{
    use SoftDeletes;

    /**
     * @var array<int, string>
     */
    protected $fillable = [
        'company_id',
        'reference',
        'bank_name',
        'holder_name',
        'account_no',
        'bank_branch',
        'swift',
        'snap',
        'type',
        'country_id',
        'created_by',
        'creator_type',
    ];

    protected $table = 'banks';

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     **/
    public function country(): HasOne
    {
        return $this->hasOne(Country::class, 'country_id', 'id');
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     **/
    public function company(): BelongsTo
    {
        return $this->BelongsTo(Company::class, 'company_id', 'id');
    }

    /**
     * @return HasMany
     */
    public function recipientTransactions(): HasMany
    {
        return $this->HasMany(Transaction::class, 'recipient_bank_account_id');
    }

    /**
     * @return MorphMany
     */
    public function attributesKVP(): MorphMany
    {
        return $this->morphMany(KeyValuePair::class, 'owner');
    }
}
