<?php

namespace App\Models;

use App\Traits\Auditable;
use App\Traits\MultiTenantModelTrait;
use DateTimeInterface;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class ContactContact extends Model
{
    use SoftDeletes, MultiTenantModelTrait, Auditable, HasFactory;

    public $table = 'contact_contacts';

    protected $dates = [
        'created_at',
        'updated_at',
        'deleted_at',
    ];

    public static $searchable = [
        'location',
        'contact_first_name',
        'contact_last_name',
        'contact_phone_1',
        'contact_phone_2',
    ];

    protected $fillable = [
        'company_id',
        'location',
        'unit_name',
        'contact_first_name',
        'contact_last_name',
        'contact_phone_1',
        'contact_phone_2',
        'contact_email',
        'created_at',
        'district',
        'pincode',
        'pan_number',
        'gstn_number',
        'department',
        'contact_address',
        'updated_at',
        'deleted_at',
        'team_id',
        'amc_engineer',
        'day'
    ];

    protected function serializeDate(DateTimeInterface $date)
    {
        return $date->format('Y-m-d H:i:s');
    }

    public function locationServiceComplaints()
    {
        return $this->hasMany(ServiceComplaint::class, 'location_id', 'id');
    }

    public function locationAssets()
    {
        return $this->belongsToMany(Asset::class);
    }

    public function company()
    {
        return $this->belongsTo(ContactCompany::class, 'company_id');
    }

    public function team()
    {
        return $this->belongsTo(Team::class, 'team_id');
    }

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


}
