<?php
namespace App;

use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Hash;

/**
 * Class User
 *
 * @package App
 * @property string $name
 * @property string $email
 * @property string $password
 * @property string $role
 * @property string $remember_token
*/
class Customer extends Authenticatable
{
    use SoftDeletes, Notifiable;

    protected $fillable = [
        'full_name',
        'email',
        'password',
        'remember_token',
        'username',
        'country',
        'mobileno',
        'aadhar',
        'ipaddress',
        'active',
        'activated_at',
        'gender',
        'panno',
        'dob',
        'city',
        'state',
        'address',
        'pincode',
        'bank_accnt_no',
        'bank_name',
        'branch_name',
        'accnt_type',
        'ifsc',
        'co_full_name',
        'co_mobile',
        'co_address',
        'co_pincode',
        'co_city',
        'co_state',
        'nom_name',
        'nom_relation',
        'nom_dob',
    ];


    /**
     * Hash password
     * @param $input
     */
    public function setPasswordAttribute($input)
    {
        if ($input)
            $this->attributes['password'] = app('hash')->needsRehash($input) ? Hash::make($input) : $input;
    }

    /**
     * Set to null if empty
     * @param $input
     */
    public function setRoleIdAttribute($input)
    {
        $this->attributes['role_id'] = $input ? $input : null;
    }

    public function role()
    {
        return $this->belongsTo(Role::class, 'role_id')->withTrashed();
    }

}
