<?php

namespace App;

class Fortuneteller extends BaseModel
{
    protected $table = 'fortune_tellers';

    protected $fillable = ['id', 'number', 'slug', 'category_id', 'shop_id', 'name', 'display_name', 'gender', 'age', 'phone_number', 'email', 'address', 'avatar',
    'desc_1_image', 'desc_1_title', 'desc_1_short', 'desc_1_full', 'desc_2_image', 'desc_2_title', 'desc_2_short', 'desc_2_full',
    'cost', 'consultation_minutes', 'performance', 'use_scry', 'consultation_genre', 'good_consultation', 'commitment', 'boom',
    'message', 'message_image', 'ref_name_id', 'user_id', 'assigned_user_id', 'preview_code', 'show_top', 'is_popular', 'is_activated', 'is_deleted', 'created_at', 'updated_at'];

    public function profile() {
        return $this->hasMany(FortuneMeta::class, 'fortune_teller_id', 'id')->select('id', 'fortune_teller_id', 'title', 'content')->where('type', 'profile');
    }

    public function info() {
        return $this->hasMany(FortuneMeta::class, 'fortune_teller_id', 'id')->select('id', 'fortune_teller_id', 'title', 'content')->where('type', 'info');
    }

    public function comment() {
        return $this->hasMany(FortuneMeta::class, 'fortune_teller_id', 'id')->select('id', 'fortune_teller_id', 'title', 'content')->where('type', 'comment')->whereNotNull('title');
    }

    public function method() {
        return $this->hasMany(FortunemethodDetail::class, 'fortune_teller_id', 'id')->select('fortune_teller_id', 'fortune_method_id');
    }

    public function methodDetail() {
        return $this->hasMany(FortunemethodDetail::class, 'fortune_teller_id', 'id')->with('detail')->select('id', 'fortune_method_id', 'fortune_teller_id');
    }

    public function consultation() {
        return $this->hasMany(ConsultationDetail::class, 'fortune_teller_id', 'id')->select('fortune_teller_id', 'consultation_id');
    }

    public function slider() {
        return $this->hasMany(FortunetellerFile::class, 'fortune_teller_id', 'id')->select('id', 'fortune_teller_id', 'name', 'file_name')->where('type', 'slider');
    }

    public function gallery() {
        return $this->hasMany(FortunetellerFile::class, 'fortune_teller_id', 'id')->select('id', 'fortune_teller_id', 'name', 'file_name')->where('type', 'gallery');
    }

    public function schedule() {
        return $this->hasMany(FortuneSchedule::class, 'fortune_teller_id', 'id');
    }

    public function review() {
        return $this->hasMany(FortuneReview::class, 'fortune_teller_id', 'id');
    }

    public function plan() {
        return $this->hasMany(FortuneSchedule::class, 'fortune_teller_id', 'id')->with('detail');
    }

    public function shop() {
        return $this->belongsTo(Shop::class, 'shop_id', 'id')->with('area');
    }

    public function shopMeta() {
        return $this->hasMany(ShopMeta::class, 'shop_id', 'shop_id')->select('id', 'shop_id', 'title', 'content');
    }

    public function tag() {
        return $this->hasMany(KeywordDetail::class, 'ref_id', 'id')->with('keyword')->select('id', 'keyword_id', 'ref_id')->where('type', 'teller');
    }
}
