<?php

namespace Database\Seeders;

use App\Models\Admin;
use App\Models\MessageTemplate;
use App\Models\User;
use App\Models\UserSetting;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Hash;

class DatabaseSeeder extends Seeder
{
    /**
     * Seed the application's database.
     */
    public function run(): void
    {
        // Create default admin
        Admin::create([
            'name' => 'Administrator',
            'email' => 'admin@autoreplysms.com',
            'password' => Hash::make('admin123'),
        ]);

        // Create a demo user
        $user = User::create([
            'name' => 'Demo User',
            'email' => 'demo@example.com',
            'phone' => '+1234567890',
            'password' => Hash::make('demo123'),
            'device_id' => 'demo-device-001',
            'api_token' => hash('sha256', 'demo-api-token'),
        ]);

        // Create default settings for demo user
        UserSetting::create([
            'user_id' => $user->id,
            'cooldown_hours' => 24,
            'exclude_contacts' => false,
            'sync_enabled' => true,
        ]);

        // Create default message template
        MessageTemplate::create([
            'user_id' => $user->id,
            'name' => 'Default Auto-Reply',
            'type' => 'auto_reply',
            'call_type' => 'all',
            'content' => 'Hi! I\'m currently unavailable. I\'ll get back to you as soon as possible. This is an automated message from AutoReply SMS.',
            'is_default' => true,
            'is_active' => true,
            'priority' => 0,
        ]);

        MessageTemplate::create([
            'user_id' => $user->id,
            'name' => 'Business Hours',
            'type' => 'auto_reply',
            'call_type' => 'missed',
            'content' => 'Thank you for your call. Our business hours are 9 AM - 5 PM. We\'ll return your call during working hours.',
            'is_default' => false,
            'is_active' => true,
            'priority' => 1,
        ]);

        MessageTemplate::create([
            'user_id' => $user->id,
            'name' => 'Special Offer',
            'type' => 'promotion',
            'call_type' => 'all',
            'content' => 'Thank you for contacting us! Check out our special offers at www.example.com',
            'is_default' => false,
            'is_active' => true,
            'priority' => 0,
        ]);

        $this->command->info('Database seeded successfully!');
        $this->command->info('Admin login: admin@autoreplysms.com / admin123');
    }
}
