<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use App\Models\PaymentGateway;
use App\Models\Currency;
use App\Models\InvoiceService;
use App\Models\InvoicePayment;
use Illuminate\Database\Eloquent\SoftDeletes;
use App\User;

class Invoice extends Model
{
    use SoftDeletes;
    
    protected $table = 'invoices';

    protected $fillable=['name','email','phone','payment_gateway','currency','due_date','slug','is_paid','status','created_by'];

    public function paymentGateway(){
        return $this->belongsTo(PaymentGateway::class, 'payment_gateway');
    }

    public function currency(){
        return $this->belongsTo(Currency::class, 'currency');
    }

    public function invoiceItems(){
        return $this->hasMany(InvoiceService::class, 'invoice_id');
    }

    public function invoicePayments(){
        return $this->hasOne(InvoicePayment::class, 'invoice_id');
    }

    
    public function createdBy(){
        return $this->belongsTo(User::class, 'created_by');
    }
    
    public function invoiceCardDecline(){
        return $this->hasMany(InvoiceCardDecline::class, 'invoice_id');
    }
}
