<?php

namespace App\Repositories\Eloquent;

use App\Models\Transaction;
use Illuminate\Support\Facades\DB;
use App\Repositories\Interfaces\TransactionRepositoryInterface;

class TransactionRepository extends BaseRepository implements TransactionRepositoryInterface
{

    /**
    * TransactionRepository constructor.
    *
    * @param Transaction $model
    */
    public function __construct(Transaction $model)
    {
       parent::__construct($model);
    }

    public function getTransactionsForDisbursement($filters)
    {
        return $this->model->select('transactions.id as transaction_id','payments.invoice',
                'payments.amount', 'payments.mop','payments.professional_fee', 'payments.convenience_fee', 'payments.desxpert_fee',
                'bookings.updated_at as completion_date', 'payments.id as payment_id'
            )
            ->leftjoin('bookings','bookings.transaction_id','=','transactions.id')
            ->leftjoin('payments','payments.id','=','transactions.payment_id')
            ->where('bookings.status','completed')
            ->where('bookings.professional_id', $filters['professional_id'])
            ->where('payments.is_disbursed', 0)
            ->where('bookings.updated_at', '>=', $filters['start_date'])
            ->where('bookings.updated_at', '<=', $filters['end_date'])
            ->get();
    }

    public function getDisbursedTransactions($disbursementId)
    {
        return $this->model->select('transactions.id as transaction_id','payments.invoice',
                'payments.amount', 'payments.mop','payments.professional_fee', 'payments.convenience_fee', 'payments.desxpert_fee',
                'bookings.updated_at as completion_date', 'payments.id as payment_id'
            )
            ->leftjoin('bookings','bookings.transaction_id','=','transactions.id')
            ->leftjoin('payments','payments.id','=','transactions.payment_id')
            ->where('payments.disbursement_id', $disbursementId)
            ->get();
    }
}
