<?php

namespace App;

class Article extends BaseModel
{
    protected $table = 'articles';

    protected $fillable = ['id', 'title', 'slug', 'description', 'editor', 'gu_content', 'content', 'thumbnail', 'category_id', 'keyword', 'tag', 'view_number', 'allow_amp', 'seo_robots', 'seo_title', 'seo_keywords', 'seo_description', 'preview', 'view_number', 'important', 'shop_id', 'fortune_teller_id', 'publish_at', 'user_id', 'is_published', 'type', 'is_activated', 'is_deleted', 'created_at', 'updated_at'];

    public function teller() {
        return $this->belongsTo(Fortuneteller::class, 'fortune_teller_id', 'id')->select('id', 'name');
    }

    public function user() {
        return $this->belongsTo(User::class, 'user_id', 'id')->select('id', 'name');
    }

    public function feature() {
        return $this->hasMany(FeatureDetail::class, 'article_id', 'id')->select('id', 'article_id', 'feature_id');
    }

    public function category() {
        return $this->hasMany(CategoryDetail::class, 'article_id', 'id')->select('id', 'article_id', 'category_id');
    }

    public function category_detail() {
        return $this->hasMany(CategoryDetail::class, 'article_id', 'id')->with('category')->select('id', 'article_id', 'category_id');
    }

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