<?php

namespace App\Models;

# use Illuminate\Database\Eloquent\Model;

use Illuminate\Database\Eloquent\Relations\HasMany;

class Customer extends Model
{
    protected $table = 'customer';

    public function client() {
        return $this->hasOne(Client::class, 'id', 'client_id');
    }

    public function company() {
        return $this->hasOne(Company::class, 'id', 'company_id');
    }

    public function invoices() {
        return $this->hasMany(Invoice::class, 'customer_id', 'id')->orderBy('created_at', 'DESC');
    }

    public function customerTransactions() {
        return $this->hasMany(CustomerTransaction::class, 'customer_id', 'id')->orderBy('created_at', 'DESC');
    }

    public function customerFinancialTransactions() {
        return $this->hasMany(FinancialTransaction::class, 'customer_id', 'id')->orderBy('created_at', 'DESC');
    }

    public function paymentMethods() {
        return $this->hasMany(PaymentMethod::class, 'customer_id', 'id')
            ->where('is_active', true)
            ->orderByRaw('created_at DESC');
    }
}
