<?php

namespace App\Models\Kb;

use App\Models\User;
use App\Traits\BelongsToStore;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class KbArticle extends Model
{
    use BelongsToStore;

    protected $fillable = [
        'store_id', 'category_id', 'title', 'content', 'author_id',
        'status', 'visibility', 'cover_image', 'attachments',
        'views', 'likes', 'favorites', 'published_at',
    ];

    protected function casts(): array
    {
        return [
            'status' => 'integer',
            'visibility' => 'integer',
            'views' => 'integer',
            'likes' => 'integer',
            'favorites' => 'integer',
            'attachments' => 'array',
            'published_at' => 'datetime',
        ];
    }

    public function category(): BelongsTo
    {
        return $this->belongsTo(KbCategory::class, 'category_id');
    }

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