<?php

namespace App\Models\Shop;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Yadahan\AuthenticationLog\AuthenticationLogable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class Customer extends Authenticatable
{
    use AuthenticationLogable, SoftDeletes;

    protected $guarded = ['id'];
    protected $table = 'shop_customers';
    protected $fillable = ['active', 'last_name', 'first_name', 'username', 'email', 'password', 'remember_token', 'settings', 'last_login'];
    protected $hidden = ['password', 'remember_token'];
    protected $casts = ['email_verified_at' => 'datetime',];

    public function addresses()
    {
        return $this->hasMany(CustomerAddress::class);
    }
    
    public function invoices()
    {
        return $this->hasMany(Invoice::class);
    }

    public function customer_deliveries()
    {
        return $this->hasMany(CustomerDelivery::class);
    }

    public function deliveries()
    {
        return $this->belongsToMany(Delivery::class, 'shop_customer_deliveries');
    }

    public function deliveries2()
    {
        return $this->hasManyThrough(Delivery::class, CustomerDelivery::class);
    }

    public function orders()
    {
        return $this->hasMany(Order::class);
    }

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