<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Spatie\Translatable\HasTranslations;

/**
 * @mixin IdeHelperBlogPost
 */
class BlogPost extends Model
{
    use HasFactory, HasTranslations;


    protected $translatable = [
        'title',
        'excerpt',
        'content'
    ];

    protected $fillable = [
        'author_id',
        'title',
        'slug',
        'excerpt',
        'content',
        'cover_image',
        'cover_image_alt',
        'category',
        'tags',
        'status',
        'is_featured',
        'reading_time',
        'view_count',
        'published_at',
        'meta',
    ];

    protected $casts = [
        'tags' => 'array',
        'meta' => 'array',
        'is_featured' => 'boolean',
        'reading_time' => 'integer',
        'view_count' => 'integer',
        'published_at' => 'datetime',
    ];

    public function author()
    {
        return $this->belongsTo(User::class,'author_id');
    }

    public function scopePublished($query)
    {
        return $query->where('status','published');
    }

    public function scopeFeatured($query)
    {
        return $query->where('is_featured',true);
    }



}
