<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;

class User extends Authenticatable
{
    use HasApiTokens, HasFactory, Notifiable;

    protected $fillable = [
        'name', 'email', 'password', 'locale', 'dark_mode',
    ];

    protected $hidden = [
        'password', 'remember_token',
    ];

    protected $casts = [
        'email_verified_at' => 'datetime',
        'dark_mode' => 'boolean',
    ];

    public function moodEntries()
    {
        return $this->hasMany(MoodEntry::class);
    }

    public function aiConversations()
    {
        return $this->hasMany(AIConversation::class);
    }

    public function subscription()
    {
        return $this->hasOne(Subscription::class)->where('is_active', true);
    }

    public function isPremium()
    {
        return $this->subscription && $this->subscription->plan !== 'free';
    }
}
