<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use App\Models\WordlingWord;
use Illuminate\Support\Facades\DB;
use Carbon\Carbon;

class WordlingWordSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        // Clear existing data (optional)
        // DB::table('wordling_words')->truncate();
        
        // Generate games for the past 100 days
        $startDate = Carbon::now()->subDays(100);
        $endDate = Carbon::now();
        
        // Common words categorized by length
        $wordLists = [
            4 => [
                'able', 'acid', 'acre', 'aged', 'also', 'area', 'army', 'away', 'baby', 'back',
                'ball', 'band', 'bank', 'base', 'bath', 'bear', 'beat', 'been', 'beer', 'bell',
                'belt', 'best', 'bill', 'bird', 'blow', 'blue', 'boat', 'body', 'bone', 'book',
                'boom', 'born', 'boss', 'both', 'bowl', 'bulb', 'burn', 'bush', 'busy', 'call',
                'calm', 'came', 'camp', 'card', 'care', 'case', 'cash', 'cast', 'cell', 'cent',
                'city', 'club', 'coal', 'coat', 'code', 'cold', 'come', 'cook', 'cool', 'copy',
                'cost', 'crew', 'crop', 'crow', 'cure', 'dark', 'data', 'date', 'dawn', 'days',
                'dead', 'deal', 'dear', 'debt', 'deep', 'deny', 'desk', 'dial', 'diet', 'disc',
                'dish', 'disk', 'does', 'done', 'door', 'dose', 'down', 'draw', 'drew', 'drop',
                'drug', 'dual', 'duck', 'duty', 'each', 'earn', 'ease', 'east', 'easy', 'edge',
                'else', 'even', 'ever', 'evil', 'exit', 'face', 'fact', 'fail', 'fair', 'fall',
                'farm', 'fast', 'fate', 'fear', 'feed', 'feel', 'feet', 'fell', 'felt', 'file',
                'fill', 'film', 'find', 'fine', 'fire', 'firm', 'fish', 'five', 'flat', 'flow',
                'food', 'foot', 'ford', 'form', 'fort', 'four', 'free', 'from', 'fuel', 'full',
                'fund', 'gain', 'game', 'gate', 'gave', 'gear', 'gene', 'gift', 'girl', 'give',
                'glad', 'goal', 'goes', 'gold', 'golf', 'gone', 'good', 'gray', 'grew', 'grey',
                'grow', 'gulf', 'hair', 'half', 'hall', 'hand', 'hang', 'hard', 'harm', 'hate',
                'have', 'head', 'hear', 'heat', 'held', 'hell', 'help', 'here', 'hero', 'high',
                'hill', 'hire', 'hold', 'hole', 'holy', 'home', 'hope', 'host', 'hour', 'huge',
                'hung', 'hunt', 'hurt', 'idea', 'inch', 'into', 'iron', 'item', 'jack', 'jane',
                'jean', 'john', 'join', 'jump', 'june', 'just', 'keen', 'keep', 'kept', 'kick',
                'kill', 'kind', 'king', 'knee', 'knew', 'know', 'lack', 'lady', 'laid', 'lake',
                'land', 'lane', 'last', 'late', 'lead', 'left', 'less', 'life', 'lift', 'like',
                'line', 'link', 'list', 'live', 'load', 'loan', 'lock', 'logo', 'long', 'look',
                'lord', 'lose', 'loss', 'lost', 'love', 'luck', 'made', 'mail', 'main', 'make',
                'male', 'many', 'mark', 'mass', 'mate', 'math', 'meal', 'mean', 'meat', 'meet',
                'menu', 'mere', 'mike', 'mile', 'milk', 'mill', 'mind', 'mine', 'miss', 'mode',
                'mood', 'moon', 'more', 'most', 'move', 'much', 'must', 'name', 'navy', 'near',
                'neck', 'need', 'news', 'next', 'nice', 'nick', 'nine', 'none', 'nose', 'note',
                'okay', 'once', 'only', 'onto', 'open', 'oral', 'over', 'pace', 'pack', 'page',
                'paid', 'pain', 'pair', 'palm', 'park', 'part', 'pass', 'past', 'path', 'peak',
                'pick', 'pink', 'pipe', 'plan', 'play', 'plot', 'plus', 'poll', 'pool', 'poor',
                'port', 'post', 'pull', 'pure', 'push', 'race', 'rail', 'rain', 'rank', 'rare',
                'rate', 'read', 'real', 'rear', 'rely', 'rent', 'rest', 'rice', 'rich', 'ride',
                'ring', 'rise', 'risk', 'road', 'rock', 'role', 'roll', 'roof', 'room', 'root',
                'rose', 'rule', 'rush', 'ruth', 'safe', 'said', 'sake', 'sale', 'salt', 'same',
                'sand', 'save', 'seat', 'seed', 'seek', 'seem', 'seen', 'self', 'sell', 'send',
                'sent', 'sept', 'ship', 'shop', 'shot', 'show', 'shut', 'sick', 'side', 'sign',
                'site', 'size', 'skin', 'slip', 'slow', 'snow', 'soft', 'soil', 'sold', 'sole',
                'some', 'song', 'soon', 'sort', 'soul', 'spot', 'star', 'stay', 'step', 'stop',
                'such', 'suit', 'sure', 'take', 'tale', 'talk', 'tall', 'tank', 'tape', 'task',
                'team', 'tech', 'tell', 'tend', 'term', 'test', 'text', 'than', 'that', 'them',
                'then', 'they', 'thin', 'this', 'thus', 'till', 'time', 'tiny', 'told', 'toll',
                'tone', 'took', 'tool', 'tour', 'town', 'tree', 'trip', 'true', 'tube', 'turn',
                'twin', 'type', 'unit', 'upon', 'used', 'user', 'vary', 'very', 'vice', 'view',
                'vote', 'wage', 'wait', 'wake', 'walk', 'wall', 'want', 'ward', 'warm', 'wash',
                'wave', 'ways', 'weak', 'wear', 'week', 'well', 'went', 'were', 'west', 'what',
                'when', 'whom', 'wide', 'wife', 'wild', 'will', 'wind', 'wine', 'wing', 'wire',
                'wise', 'wish', 'with', 'wood', 'word', 'work', 'yard', 'yeah', 'year', 'your'
            ],
            5 => [
                'about', 'above', 'abuse', 'actor', 'acute', 'admit', 'adopt', 'adult', 'after', 'again',
                'agent', 'agree', 'ahead', 'alarm', 'album', 'alert', 'alien', 'align', 'alive', 'allow',
                'alone', 'along', 'alter', 'angel', 'anger', 'angle', 'angry', 'apart', 'apple', 'apply',
                'arena', 'argue', 'arise', 'array', 'aside', 'asset', 'audio', 'audit', 'avoid', 'award',
                'aware', 'badly', 'baker', 'bases', 'basic', 'beach', 'began', 'being', 'below', 'bench',
                'billy', 'birth', 'black', 'blame', 'blind', 'block', 'blood', 'board', 'boost', 'booth',
                'bound', 'brain', 'brand', 'brave', 'bread', 'break', 'breed', 'brief', 'bring', 'broad',
                'broke', 'brown', 'build', 'built', 'buyer', 'cable', 'calif', 'carry', 'catch', 'cause',
                'chain', 'chair', 'chaos', 'charm', 'chart', 'chase', 'cheap', 'check', 'chest', 'chief',
                'child', 'china', 'chose', 'civil', 'claim', 'class', 'clean', 'clear', 'click', 'clock',
                'close', 'cloud', 'coach', 'coast', 'could', 'count', 'court', 'cover', 'craft', 'crash',
                'crazy', 'cream', 'crime', 'cross', 'crowd', 'crown', 'crude', 'curve', 'cycle', 'daily',
                'dance', 'dated', 'dealt', 'death', 'debts', 'debug', 'debut', 'delay', 'depth', 'doing',
                'doubt', 'dozen', 'draft', 'drama', 'drank', 'drawn', 'dream', 'dress', 'drill', 'drink',
                'drive', 'drove', 'dying', 'eager', 'early', 'earth', 'eight', 'elite', 'empty', 'enemy',
                'enjoy', 'enter', 'entry', 'equal', 'error', 'event', 'every', 'exact', 'exist', 'extra',
                'faith', 'false', 'fault', 'fiber', 'field', 'fifth', 'fifty', 'fight', 'final', 'first',
                'fixed', 'flash', 'fleet', 'floor', 'fluid', 'focus', 'force', 'forth', 'forty', 'forum',
                'found', 'frame', 'frank', 'fraud', 'fresh', 'front', 'fruit', 'fully', 'funny', 'giant',
                'given', 'glass', 'globe', 'going', 'grace', 'grade', 'grand', 'grant', 'grass', 'grave',
                'great', 'green', 'gross', 'group', 'grown', 'guard', 'guess', 'guest', 'guide', 'happy',
                'harry', 'heart', 'heavy', 'hello', 'henry', 'horse', 'hotel', 'house', 'human', 'ideal',
                'image', 'imply', 'index', 'inner', 'input', 'issue', 'japan', 'jimmy', 'joint', 'jones',
                'judge', 'known', 'label', 'large', 'laser', 'later', 'laugh', 'layer', 'learn', 'lease',
                'least', 'leave', 'legal', 'lemon', 'level', 'lewis', 'light', 'limit', 'links', 'lives',
                'local', 'logic', 'loose', 'lower', 'lucky', 'lunch', 'lying', 'magic', 'major', 'maker',
                'march', 'maria', 'match', 'maybe', 'mayor', 'meant', 'media', 'metal', 'might', 'minor',
                'minus', 'mixed', 'model', 'money', 'month', 'moral', 'motor', 'mount', 'mouse', 'mouth',
                'moved', 'movie', 'music', 'needs', 'never', 'newly', 'night', 'noise', 'north', 'noted',
                'novel', 'nurse', 'occur', 'ocean', 'offer', 'often', 'order', 'other', 'ought', 'outer',
                'owner', 'paint', 'panel', 'paper', 'party', 'peace', 'penny', 'peter', 'phase', 'phone',
                'photo', 'piano', 'piece', 'pilot', 'pitch', 'place', 'plain', 'plane', 'plant', 'plate',
                'point', 'pound', 'power', 'press', 'price', 'pride', 'prime', 'print', 'prior', 'prize',
                'proof', 'proud', 'prove', 'queen', 'quick', 'quiet', 'quite', 'radio', 'raise', 'range',
                'rapid', 'ratio', 'reach', 'ready', 'realm', 'refer', 'relax', 'repay', 'reply', 'right',
                'rival', 'river', 'robin', 'rocky', 'roger', 'roman', 'rough', 'round', 'route', 'royal',
                'rural', 'scale', 'scene', 'scope', 'score', 'screw', 'sense', 'serve', 'seven', 'shall',
                'shape', 'share', 'sharp', 'sheet', 'shelf', 'shell', 'shift', 'shine', 'shirt', 'shock',
                'shoot', 'short', 'shown', 'sight', 'silver', 'similar', 'simple', 'since', 'sixth', 'sixty',
                'sized', 'skill', 'slash', 'sleep', 'slide', 'small', 'smart', 'smile', 'smith', 'smoke',
                'solid', 'solve', 'sorry', 'sound', 'south', 'space', 'spare', 'speak', 'speed', 'spend',
                'spent', 'split', 'spoke', 'sport', 'staff', 'stage', 'stake', 'stand', 'start', 'state',
                'steam', 'steel', 'steep', 'steer', 'stick', 'still', 'stock', 'stone', 'stood', 'store',
                'storm', 'story', 'strip', 'stuck', 'study', 'stuff', 'style', 'sugar', 'suite', 'sunny',
                'super', 'surge', 'sweet', 'swift', 'swing', 'sword', 'table', 'taken', 'taste', 'taxes',
                'teach', 'teeth', 'tempo', 'texas', 'thank', 'theft', 'their', 'theme', 'there', 'these',
                'thick', 'thing', 'think', 'third', 'those', 'three', 'threw', 'throw', 'thumb', 'tight',
                'timer', 'title', 'today', 'topic', 'total', 'touch', 'tough', 'tower', 'track', 'trade',
                'train', 'trash', 'treat', 'trend', 'trial', 'tribe', 'trick', 'tried', 'tries', 'truck',
                'truly', 'trust', 'truth', 'twice', 'twist', 'tyler', 'uncle', 'under', 'undue', 'union',
                'unity', 'until', 'upper', 'upset', 'urban', 'usage', 'usual', 'valid', 'value', 'video',
                'virus', 'visit', 'vital', 'vocal', 'voice', 'wagon', 'waste', 'watch', 'water', 'wheel',
                'where', 'which', 'while', 'white', 'whole', 'whose', 'woman', 'women', 'world', 'worry',
                'worse', 'worst', 'worth', 'would', 'wound', 'write', 'wrong', 'wrote', 'yield', 'young',
                'youth'
            ],
            7 => [
                'ability', 'absence', 'academy', 'account', 'accused', 'achieve', 'acquire', 'address', 'advance', 'adverse',
                'advised', 'adviser', 'against', 'airline', 'airport', 'alcohol', 'alleged', 'already', 'analyst', 'ancient',
                'another', 'anxiety', 'anxious', 'anybody', 'applied', 'arrange', 'arrival', 'article', 'assault', 'assumed',
                'assured', 'attempt', 'attract', 'auction', 'average', 'backing', 'balance', 'banking', 'barrier', 'battery',
                'bearing', 'beating', 'because', 'bedroom', 'believe', 'beneath', 'benefit', 'besides', 'between', 'billion',
                'binding', 'brother', 'brought', 'burning', 'cabinet', 'caliber', 'calling', 'capable', 'capital', 'captain',
                'caption', 'capture', 'careful', 'carrier', 'caution', 'ceiling', 'central', 'centric', 'century', 'certain',
                'chamber', 'channel', 'chapter', 'charity', 'charlie', 'charter', 'checked', 'chicken', 'chronic', 'circuit',
                'classes', 'classic', 'climate', 'closing', 'closure', 'clothes', 'collect', 'college', 'combine', 'comfort',
                'command', 'comment', 'compact', 'company', 'compare', 'compete', 'complex', 'concept', 'concern', 'concert',
                'conduct', 'confirm', 'connect', 'consent', 'consist', 'contact', 'contain', 'content', 'contest', 'context',
                'control', 'convert', 'correct', 'council', 'counsel', 'counter', 'country', 'crucial', 'crystal', 'culture',
                'current', 'cutting', 'dealing', 'decided', 'decline', 'default', 'defence', 'defense', 'deficit', 'deliver',
                'density', 'deposit', 'desktop', 'despite', 'destroy', 'develop', 'devoted', 'diamond', 'digital', 'discuss',
                'disease', 'display', 'dispute', 'distant', 'diverse', 'divided', 'drawing', 'driving', 'dynamic', 'eastern',
                'economy', 'edition', 'elderly', 'element', 'engaged', 'enhance', 'essence', 'evening', 'evident', 'exactly',
                'examine', 'example', 'excited', 'exclude', 'exhibit', 'expense', 'explain', 'explore', 'express', 'extreme',
                'factory', 'faculty', 'failing', 'failure', 'fashion', 'feature', 'federal', 'feeling', 'fiction', 'fifteen',
                'filling', 'finance', 'finding', 'fishing', 'fitness', 'foreign', 'forever', 'formula', 'fortune', 'forward',
                'founder', 'freedom', 'further', 'gallery', 'gateway', 'general', 'genetic', 'genuine', 'gigabit', 'greater',
                'hanging', 'heading', 'healthy', 'hearing', 'heavily', 'helpful', 'helping', 'herself', 'highway', 'himself',
                'history', 'holding', 'holiday', 'housing', 'however', 'hundred', 'husband', 'illegal', 'illness', 'imagine',
                'imaging', 'improve', 'include', 'initial', 'inquiry', 'insight', 'install', 'instant', 'instead', 'intense',
                'interim', 'involve', 'jointly', 'journal', 'journey', 'justice', 'justify', 'keeping', 'killing', 'kingdom',
                'kitchen', 'knowing', 'landing', 'largely', 'lasting', 'leading', 'learned', 'leisure', 'liberal', 'liberty',
                'library', 'license', 'limited', 'listing', 'logical', 'loyalty', 'machine', 'manager', 'married', 'massive',
                'maximum', 'meaning', 'measure', 'medical', 'meeting', 'mention', 'message', 'million', 'mineral', 'minimal',
                'minimum', 'missing', 'mission', 'mistake', 'mixture', 'monitor', 'monthly', 'morning', 'musical', 'mystery',
                'natural', 'neither', 'nervous', 'network', 'neutral', 'notable', 'nothing', 'nowhere', 'nuclear', 'nursing',
                'obvious', 'offense', 'officer', 'ongoing', 'opening', 'operate', 'opinion', 'optical', 'organic', 'outcome',
                'outdoor', 'outline', 'outside', 'overall', 'pacific', 'package', 'painted', 'parking', 'partial', 'partner',
                'passage', 'passing', 'passion', 'passive', 'patient', 'pattern', 'payable', 'payment', 'penalty', 'pending',
                'pension', 'percent', 'perfect', 'perform', 'perhaps', 'phoenix', 'picking', 'picture', 'pioneer', 'plastic',
                'pointed', 'popular', 'portion', 'poverty', 'precise', 'predict', 'premier', 'premium', 'prepare', 'present',
                'prevent', 'primary', 'printer', 'privacy', 'private', 'problem', 'proceed', 'process', 'produce', 'product',
                'profile', 'program', 'project', 'promise', 'promote', 'protect', 'protein', 'protest', 'provide', 'publish',
                'purpose', 'pushing', 'qualify', 'quality', 'quarter', 'radical', 'railway', 'readily', 'reading', 'reality',
                'realize', 'receipt', 'receive', 'recover', 'reflect', 'regular', 'related', 'release', 'remains', 'removal',
                'removed', 'replace', 'request', 'require', 'reserve', 'resolve', 'respect', 'respond', 'restore', 'retired',
                'revenue', 'reverse', 'rollout', 'routine', 'running', 'satisfy', 'science', 'section', 'segment', 'serious',
                'service', 'serving', 'session', 'setting', 'seventh', 'several', 'shortly', 'showing', 'silence', 'silicon',
                'similar', 'sitting', 'sixteen', 'skilled', 'smoking', 'society', 'somehow', 'someone', 'speaker', 'special',
                'species', 'sponsor', 'station', 'storage', 'strange', 'stretch', 'student', 'studied', 'subject', 'succeed',
                'success', 'suggest', 'summary', 'support', 'suppose', 'supreme', 'surface', 'surgery', 'surplus', 'survive',
                'suspect', 'sustain', 'teacher', 'telecom', 'telling', 'tension', 'theatre', 'therapy', 'thereby', 'thought',
                'through', 'tobacco', 'tonight', 'totally', 'touched', 'towards', 'traffic', 'trouble', 'turning', 'typical',
                'uniform', 'unknown', 'unusual', 'upgrade', 'upscale', 'utility', 'variety', 'various', 'vehicle', 'venture',
                'version', 'veteran', 'victory', 'viewing', 'village', 'violent', 'virtual', 'visible', 'waiting', 'walking',
                'wanting', 'warning', 'warrant', 'wearing', 'weather', 'webcast', 'website', 'wedding', 'weekend', 'welcome',
                'welfare', 'western', 'whereas', 'whereby', 'whether', 'willing', 'winning', 'without', 'witness', 'working',
                'writing', 'written'
            ]
        ];
        
        // Game type configurations with numeric codes
        $gameTypes = [
            'wordling_min' => [
                'word_length' => 4,
                'max_attempts' => 5,
                'word_list' => $wordLists[4],
                'type_code' => 1 // Numeric code for min
            ],
            'wordling_main' => [
                'word_length' => 5,
                'max_attempts' => 6,
                'word_list' => $wordLists[5],
                'type_code' => 2 // Numeric code for main
            ],
            'wordling_max' => [
                'word_length' => 7,
                'max_attempts' => 10,
                'word_list' => $wordLists[7],
                'type_code' => 3 // Numeric code for max
            ]
        ];
        
        // Counter for generating unique IDs
        $counter = 1000;
        
        // Generate games for each day in the date range
        for ($date = $startDate->copy(); $date->lte($endDate); $date->addDay()) {
            // Skip weekends if desired
            // if ($date->isWeekend()) continue;
            
            // Create one game for each game type per day
            foreach ($gameTypes as $gameType => $config) {
                // Generate a numeric game_id using date + type code + counter
                $gameId = (int)($date->format('Ymd') . $config['type_code'] . $counter);
                $counter++;
                
                // Pick a random word from the appropriate word list
                $secretWord = $config['word_list'][array_rand($config['word_list'])];
                
                // Create the game
                WordlingWord::create([
                    'game_id' => $gameId,
                    'secret_word' => $secretWord,
                    'secret_word_length' => $config['word_length'],
                    'max_attempts' => $config['max_attempts'],
                    'game_type' => $gameType,
                    'game_date' => $date->toDateString(),
                ]);
            }
        }
        
        $this->command->info('Wordling games seeded successfully with all three game types!');
    }
}