<?php

namespace App\Models;

use App\Models\Concerns\HasOwnerScope;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class SubscriptionItem extends Model
{
    use HasOwnerScope;

    protected $fillable = [
        'user_id',
        'external_id',
        'name',
        'category_id',
        'cost',
        'billing_cycle',
        'next_renewal',
        'last_charge',
        'status',
        'confidence',
        'usage_score',
        'notes',
    ];

    protected function casts(): array
    {
        return [
            'cost' => 'float',
            'next_renewal' => 'date',
            'last_charge' => 'date',
            'confidence' => 'integer',
            'usage_score' => 'integer',
        ];
    }

    public function user(): BelongsTo
    {
        return $this->belongsTo(User::class);
    }
}
