<?php

namespace App;

use Laravel\Passport\HasApiTokens;
use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Laravel\Cashier\Billable;

class Customers extends Authenticatable {

    use HasApiTokens,
        Notifiable;
    use Billable;

    protected $table = 'customers';
    protected $primaryKey = 'id';
    protected $guarded = ['id'];
    protected $guard = 'customers';
    protected $fillable = ['title', 'firstName', 'lastName', 'phone', 'status', 'type', 'email'];
    protected $hidden = ['password', 'remember_token'];

    protected $attributes = [
        'status' => 0,
    ];
    public function address() {
        return $this->belongsTo('App\Addresses', 'id', 'customer_id');
    }

    public function transaction() {
        return $this->belongsTo('App\Transactions', 'id', 'customer_id');
    }


    public function getStatusAttribute($value)
    {
        return $value ? 'Active' : 'Inactive';
    }

    // Define the mutator
    public function setStatusAttribute($value)
    {
        $this->attributes['status'] = $value ? 1 : 0;
    }
}
