<?php

namespace App;

use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;

class User extends Authenticatable
{
	use Notifiable;
	
	/**
	 * The attributes that are mass assignable.
	 *
	 * @var array
	 */
	protected $fillable = [
		'name', 'slug', 'first_name', 'last_name', 'full_name', 'furigana_name', 'furigana_first_name', 'furigana_last_name',
		'username', 'email', 'email2', 'password', 'avatar', 'gender', 'career', 'date_of_birth', 'age', 'post_code', 'city', 'district', 'address', 'address2',
		'phone_number', 'fax_number', 'mobile_tel', 'emg_tel', 'introduction', 'reminder_question', 'reminder_answer', 'line_id', 'point', 'point_rate',
		'driver_license', 'insurance_card', 'number_card', 'shipping_post_code', 'shipping_city', 'shipping_district', 'shipping_address', 'shipping_address2',
		'is_leader', 'is_allowed_record_single', 'is_allowed_report_single', 'is_allowed_record_group', 'is_allowed_report_group', 'time_allowed_record',
		'reset_password_code', 'reset_password_time', 'email_verified_at', 'email_subscribe', 'email_format', 'login_url', 'is_online', 'last_activity',
		'fcm_token', 'push_notifications_enabled', 'pwa_endpoint', 'pwa_p256dh', 'pwa_auth', 'pwa_user_agent', 'pwa_platform',
		'is_temp', 'is_activated', 'is_deleted', 'created_by', 'created_at', 'updated_at',
	];
	
	/**
	 * The attributes that should be hidden for arrays.
	 *
	 * @var array
	 */
	protected $hidden = [
		'password', 'remember_token',
	];
	
	/**
	 * The attributes that should be cast to native types.
	 *
	 * @var array
	 */
	protected $casts = [
		'email_verified_at'          => 'datetime',
		'is_online'                  => 'boolean',
		'last_activity'              => 'datetime',
		'push_notifications_enabled' => 'boolean'
	];
	
	public function projects()
	{
		return $this->hasMany(UserProject::class, 'user_id', 'id')->with('project', 'members');
	}
	
	public function conversations()
	{
		return $this->hasMany(UserConversation::class, 'user_id', 'id');
	}
}
