<?php

namespace App\Models;

use Illuminate\Database\Eloquent\SoftDeletes;
use Slowlyo\OwlAdmin\Models\BaseModel as Model;

/**
 * 技师
 */
class CoachUser extends Model
{
	use SoftDeletes;

	protected $table = 'coach_users';

    protected $guarded = [];

    protected static function booted()
	{
		static::created(function ($user) {
			$user->wallet()->create([
				'owner_type' => CoachUser::class,
				'owner_id' => $user->id
			]);
		});
	}

    /**
     * @Author FelixYin
     * @description 技师所属会员
     */
    public function member()
    {
        return $this->belongsTo('App\Models\MemberUser', 'user_id');
    }

    /**
     * @Author FelixYin
     * @description 技师关联信息
     */
    public function info()
    {
        return $this->hasOne('App\Models\CoachInfoRecord', 'id', 'info_record_id');
    }

    /**
     * @Author FelixYin
     * @description 技师关联资质信息
     */
    public function qual()
    {
        return $this->hasOne('App\Models\CoachQualRecord', 'id', 'qualification_record_id');
    }

    /**
     * @Author FelixYin
     * @description 技师关联评分
     */
    public function score()
    {
        return $this->hasOne('App\Models\CoachScore', 'coach_id', 'id');
    }

    /**
     * @Author FelixYin
     * @description 技师关联定位
     */
    public function locations()
    {
        return $this->hasMany('App\Models\CoachLocation', 'coach_id', 'id');
    }

    /**
     * @Author FelixYin
     * @description 技师关联订单
     */
    public function orders()
    {
        return $this->hasMany('App\Models\OrderInfo', 'coach_id', 'id');
    }

    /**
     * @Author FelixYin
     * @description 技师关联抢单记录
     */
    public function grabRecords()
    {
        return $this->hasMany('App\Models\OrderGrabRecord', 'coach_id', 'id');
    }

    /**
     * @Author FelixYin
     * @description 技师关联评论
     */
    public function comments()
    {
        return $this->hasMany('App\Models\OrderComment', 'coach_id', 'id');
    }

    /**
     * @Author FelixYin
     * @description 技师关联钱包
     */
    public function wallet()
    {
        return $this->MORPH_ONE('App\Models\Wallet', 'undefined');
    }

    /**
     * @Author FelixYin
     * @description 技师所属店铺
     */
    public function shop()
    {
        return $this->belongsTo('App\Models\ShopInfo', 'shop_id', 'shop_id');
    }

    /**
     * @Author FelixYin
     * @description 技师关联店铺开通服务
     */
    public function shopOpenService()
    {
        return $this->hasMany('App\Models\ShopCoachService', 'coach_id', 'id');
    }

    /**
     * @Author FelixYin
     * @description 技师关联实名信息
     */
    public function real()
    {
        return $this->hasOne('App\Models\CoachRealAuthRecord', 'id', 'real_auth_record_id');
    }

    /**
     * @Author FelixYin
     * @description 技师开通项目
     */
    public function projects()
    {
        return $this->hasMany('App\Models\CoachProject', 'coach_id', 'id');
    }

    /**
     * @Author FelixYin
     * @description 基本信息认证记录
     */
    public function infoRecords()
    {
        return $this->hasMany('App\Models\CoachInfoRecord', 'coach_id', 'id');
    }

    /**
     * @Author FelixYin
     * @description 技师关联资质记录
     */
    public function qualRecords()
    {
        return $this->hasMany('App\Models\CoachQualRecord', 'coach_id', 'id');
    }

    /**
     * @Author FelixYin
     * @description 技师关联实名认证记录
     */
    public function realAuthRecords()
    {
        return $this->hasMany('App\Models\CoachRealAuthRecord', 'coach_id', 'id');
    }
}
