<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use App\Models\User;
use App\Models\SocialAccount;
use App\Models\Post;
use App\Models\PostPlatform;
use App\Models\ActivityLog;
use Illuminate\Support\Facades\Hash;

class DatabaseSeeder extends Seeder
{
    public function run(): void
    {
        // Create admin user
        $admin = User::create([
            'name' => 'Admin User',
            'email' => 'admin@socialscheduler.com',
            'password' => Hash::make('admin123'),
            'role' => 'admin',
        ]);

        // Create regular user
        $user = User::create([
            'name' => 'John Doe',
            'email' => 'john@example.com',
            'password' => Hash::make('password123'),
            'role' => 'user',
        ]);

        // Create social accounts for user
        SocialAccount::create([
            'user_id' => $user->id,
            'platform_name' => 'facebook',
            'account_name' => 'JohnDoeFB',
            'access_token' => 'mock_token_facebook_' . uniqid(),
            'status' => 'active',
        ]);

        SocialAccount::create([
            'user_id' => $user->id,
            'platform_name' => 'twitter',
            'account_name' => '@JohnDoeX',
            'access_token' => 'mock_token_twitter_' . uniqid(),
            'status' => 'active',
        ]);

        SocialAccount::create([
            'user_id' => $user->id,
            'platform_name' => 'linkedin',
            'account_name' => 'john-doe-linkedin',
            'access_token' => 'mock_token_linkedin_' . uniqid(),
            'status' => 'active',
        ]);

        // Create sample posts
        Post::create([
            'user_id' => $user->id,
            'content' => '🚀 Excited to share our latest product update! Check it out.',
            'status' => 'published',
            'published_at' => now()->subDays(2),
            'publish_log' => 'Published successfully to all platforms.',
        ]);

        Post::create([
            'user_id' => $user->id,
            'content' => 'Join us for our upcoming webinar on digital marketing strategies! 📅',
            'status' => 'scheduled',
            'scheduled_at' => now()->addDays(1),
        ]);

        Post::create([
            'user_id' => $user->id,
            'content' => 'Draft post - still working on the content...',
            'status' => 'draft',
        ]);

        ActivityLog::create([
            'user_id' => $admin->id,
            'action' => 'seed',
            'model_type' => 'App\Models\User',
            'model_id' => $admin->id,
            'description' => 'Database seeded with default data',
        ]);
    }
}
