<?php

namespace App\Models;

use App\Classes\General\Traits\LogData;
use Illuminate\Database\Eloquent\Model;
use App\Classes\General\Interfaces\Documentable;
use App\Classes\General\Interfaces\Transactionable;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use Illuminate\Database\Eloquent\SoftDeletes;
use Staudenmeir\EloquentHasManyDeep\HasManyDeep;
use Staudenmeir\EloquentHasManyDeep\HasRelationships;

class BillGroup extends Model implements Documentable, Transactionable
{
    use SoftDeletes;

    protected $table = 'bill_groups';

    /**
     * Get the attributes that should be cast.
     *
     * @return array<string, string>
     */
    protected function casts(): array
    {
        return [
            'deleted_at' => 'datetime',
        ];
    }

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

    use HasRelationships;
    use \Staudenmeir\EloquentHasManyDeep\HasTableAlias;

	public function billRefunds()
    {
        return $this->belongsToMany(Transaction::class, BillGroupRefund::class);
    }

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

     /**
     * @return BelongsTo
     */
    public function currency(): BelongsTo
    {
        return $this->BelongsTo(Currency::class, 'currency_id', 'id');
    }

    /**
     * @return BelongsTo
     */
    public function issuerCompany(): BelongsTo
    {
        return $this->BelongsTo( Company::class, 'issuer', 'id');
    }

    /**
     * @return BelongsTo
     */
    public function original_currency(): BelongsTo
    {
        return $this->BelongsTo(Currency::class, 'original_currency_id', 'id');
    }

    public function groups()
    {
        return $this->belongsToMany(Group::class, BillGroupPayment::class, 'bill_group_id', 'group_id');
    }
}
