<?php

namespace App\Models;

use App\Http\Controllers\ReceiptController;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Receipt extends Model
{
    use HasFactory,softDeletes;

    protected $table = 'acc_receipts';

    protected $guarded = ['id'];

    /**Each Receipt is of a Particuler Type**/
    public function receiptType($rctType){
        return 'OFFICIAL RECEIPT';
    }

    /**A Receipt is Posted by a Single User**/
    public function user(){
        return $this->belongsTo(User::class, 'created_by', 'id');
    }

    /**A Receipt is Reversed by a Single User**/
    public function reversedBy(){
        return $this->belongsTo(User::class, 'reversed_by', 'id');
    }

    /**A Receipt is affiliated to a specific Bank Account**/
    public function account(){
        return $this->belongsTo(CompanyChartsOfAccount::class, 'acc_id', 'id');
    }

    /**A Premium Receipt is Made by a Single Client if type is Premium**/
    public function client(){
        return $this->belongsTo(Client::class, 'c_id', 'c_id');
    }


    /**A Receipt has a particular Mode of Payment**/
    public function modeOfPayment(){
        return $this->belongsTo(CompanyMainPaymentMode::class, 'mode', 'id');
    }

    /**A Receipt has a Particular Sub-Mode of Payment; If any**/
    public function subModeOfPayment(){
        return $this->belongsTo(CompanySubModesOfPayment::class, 'sub_mode', 'id');
    }

    /**A Receipt is Done in a specific Currency**/
    public function currencyDetails(){
        return $this->belongsTo(CompanyCurrency::class, 'currency', 'id');
    }

    /**Premium Receipt Balance**/
    public function premiumReceiptBalance($id){
        return (new ReceiptController)->premiumReceiptBalance($id);
    }

}
