<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;

class CustomAccount extends Model
{
    use SoftDeletes;

    protected $fillable = [
        'name', 'email', 'account_type', 'notes', 'opening_balance', 'created_by', 'updated_by'
    ];

    public function creator(): BelongsTo
    {
        return $this->belongsTo(User::class, 'created_by');
    }

    public function updater(): BelongsTo
    {
        return $this->belongsTo(User::class, 'updated_by');
    }

    public function cashIns(): HasMany
    {
        return $this->hasMany(CashIn::class);
    }

    public function cashOuts(): HasMany
    {
        return $this->hasMany(CashOut::class);
    }

    public function consignments(): HasMany
    {
        return $this->hasMany(Consignment::class, 'investor_custom_account_id');
    }

    public function buyerConsignments(): HasMany
    {
        return $this->hasMany(Consignment::class, 'buyer_custom_account_id');
    }

    public function sellerConsignments(): HasMany
    {
        return $this->hasMany(Consignment::class, 'seller_custom_account_id');
    }
}