<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Contact extends Model
{
    use HasFactory;

    public function source()
    {
        return $this->belongsTo('App\Models\Attribute', 'source_id');
    }

    public function contact_role()
    {
        return $this->belongsTo('App\Models\Attribute', 'contact_role_id');
    }

    public function enquiry_source()
    {
        return $this->belongsTo('App\Models\Attribute', 'enquiry_source_id');
    }

    public function assignee()
    {
        return $this->belongsTo('App\Models\User', 'assign_to');
    }

    public function logs()
    {
        return $this->hasMany('App\Models\Logs', 'model_id')
            ->where('model_name', 'contacts')
            ->with('user')->orderByDesc('created_at');
    }

    public function contact_documents()
    {
        return $this->hasMany('App\Models\ContactDocument')->with('user')->orderByDesc('created_at');
    }

    public function contact_streams()
    {
        return $this->hasMany('App\Models\ContactNote')->where('type', 1)->orderByDesc('created_at');
    }

    public function appointments()
    {
        return $this->hasMany('App\Models\Appointment')->orderByDesc('created_at');
    }

    public function contact_reminders()
    {
        return $this->hasMany('App\Models\ContactNote')->where('type', 2)->orderByDesc('created_at');
    }
    public function contact_feedbacks()
    {
        return $this->hasMany('App\Models\ContactNote')->where('type', 3)->orderByDesc('created_at');
    }

    public function contact_listings()
    {
        return $this->hasMany('App\Models\ContactListing', 'contact_id')->orderByDesc('created_at');
    }

    public function contact_relations()
    {
        return $this->hasMany('App\Models\ContactRelation', 'contact_id')->orderByDesc('created_at');
    }

    public function contact_reqs()
    {
        return $this->hasMany('App\Models\ContactRequirement', 'contact_id')->orderByDesc('created_at');
    }
}
