<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class KeywordRecommendation extends Model
{
    use HasFactory;

    protected $fillable = [
        'page_id',
        'keyword',
        'is_primary',
        'composite_score',
        'ai_relevance_score',
        'search_volume',
        'competition',
        'competition_index',
        'cpc',
        'intent',
        'reasoning',
    ];

    protected $casts = [
        'is_primary' => 'boolean',
        'composite_score' => 'decimal:2',
        'ai_relevance_score' => 'decimal:2',
        'cpc' => 'decimal:2',
    ];

    public function page()
    {
        return $this->belongsTo(Page::class);
    }

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

    public function scopeSecondary($query)
    {
        return $query->where('is_primary', false);
    }

    public function scopeOrderedByScore($query)
    {
        return $query->orderBy('composite_score', 'desc');
    }
}
