<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;

class Challenge extends Model
{
    protected $fillable = [
        'title',
        'description',
        'rules',
        'rewards',
        'duration_days',
        'is_active',
    ];

    protected function casts(): array
    {
        return [
            'duration_days' => 'integer',
            'is_active' => 'boolean',
        ];
    }

    public static function defaultChallenge(): self
    {
        return self::query()->firstOrCreate(
            ['title' => '30-Day Trading Discipline Challenge'],
            [
                'description' => 'Journal every trading day, review discipline, and build a stronger trading routine.',
                'rules' => 'Journal trades honestly, review your risk decisions, and keep your notes updated during the challenge.',
                'rewards' => 'Earn discipline badges as you build consistency.',
                'duration_days' => 30,
                'is_active' => true,
            ]
        );
    }

    public function participants(): HasMany
    {
        return $this->hasMany(ChallengeParticipant::class);
    }
}
