ledgerrz/database/seeders/DatabaseSeeder.php

171 lines
8.7 KiB
PHP

<?php
namespace Database\Seeders;
use App\Models\User;
use App\Models\Dynamic;
use App\Models\Ledger;
use App\Models\Mutation;
use App\Models\Message;
use App\Services\ActivityService;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\DB;
class DatabaseSeeder extends Seeder
{
/**
* Seed the application's database.
*/
public function run(ActivityService $activityService): void
{
DB::transaction(function () use ($activityService) {
// 1. Create Core Users
$testUser = User::factory()->create([
'name' => 'Test User',
'email' => 'test@example.com',
'password' => Hash::make('password'),
]);
$alice = User::factory()->create([
'name' => 'Domina Alice',
'email' => 'alice@example.com',
'password' => Hash::make('password'),
]);
$bob = User::factory()->create([
'name' => 'Submissive Bob',
'email' => 'bob@example.com',
'password' => Hash::make('password'),
]);
$charles = User::factory()->create([
'name' => 'Master Charles',
'email' => 'charles@example.com',
'password' => Hash::make('password'),
]);
// Create some random general users
User::factory(5)->create();
// ----------------------------------------------------
// 2. Seed Dynamic 1: The Velvet Sanctuary
// ----------------------------------------------------
$velvetSanctuary = Dynamic::create([
'name' => 'The Velvet Sanctuary',
'rules' => "1. Respect limits and boundaries at all times.
2. Submit daily logs for curfew and chores.
3. Maintain proper protocol in the general discussion.",
]);
// Add participants (Test User is owner, Alice is owner, Bob is submissive/participant)
$velvetSanctuary->participants()->attach($testUser->id, ['role' => 'owner']);
$velvetSanctuary->participants()->attach($alice->id, ['role' => 'owner']);
$velvetSanctuary->participants()->attach($bob->id, ['role' => 'participant']);
// Chat has been auto-created by the booted hook on Dynamic
$velvetChat = $velvetSanctuary->chat;
// Seed Dynamic Chat Messages
$activityService->createMessage($velvetChat, $alice, 'Good morning everyone. Bob, please ensure the Obsidian room is polished before 4 PM.');
$activityService->createMessage($velvetChat, $testUser, 'I will review the curfew log later today.');
$activityService->createMessage($velvetChat, $bob, "Yes, Sir. Yes, Ma'am. I am starting on the chores now.");
$activityService->createMessage($velvetChat, $testUser, 'Excellent. Keep up the high standard.');
// Add Ledgers
$curfewLedger = Ledger::create([
'dynamic_id' => $velvetSanctuary->id,
'name' => 'Curfew Compliance',
'rules' => 'Must be in bed and checked in by 11:00 PM.',
'score' => 35,
'alignment' => 'positive',
]);
$cleaningLedger = Ledger::create([
'dynamic_id' => $velvetSanctuary->id,
'name' => 'Dungeon Cleaning',
'rules' => 'Earn +10 to +20 points for cleaning/setup. Penalty -10 for disorganization.',
'score' => 45,
'alignment' => 'neutral',
]);
$etiquetteLedger = Ledger::create([
'dynamic_id' => $velvetSanctuary->id,
'name' => 'Protocol & Etiquette',
'rules' => 'Address others by correct titles. +5 per infraction.',
'score' => 15,
'alignment' => 'negative',
]);
// Seed Curfew Mutations
$activityService->createMutation($curfewLedger, $bob, 'reward', 10, 'Checked in by 10:45 PM on Friday', 'approved');
$activityService->createMutation($curfewLedger, $bob, 'reward', 15, 'Checked in by 10:30 PM on Saturday', 'approved');
$activityService->createMutation($curfewLedger, $bob, 'reward', 10, 'Checked in by 10:50 PM on Sunday', 'approved');
// Seed Cleaning Mutations
$activityService->createMutation($cleaningLedger, $bob, 'reward', 15, 'Deep cleaning of the main chamber', 'approved');
$activityService->createMutation($cleaningLedger, $bob, 'reward', 20, 'Arranged gear rack and polished leather accessories', 'approved');
$activityService->createMutation($cleaningLedger, $bob, 'reward', 10, 'Mopped obsidian floors', 'approved');
$activityService->createMutation($cleaningLedger, $alice, 'penalty', -10, 'Left keys in the locks unmonitored', 'approved');
// Seed Pending Mutation with its own Chat Messages!
$pendingMutation = $activityService->createMutation($cleaningLedger, $bob, 'addition', 10, 'Weekly chore submission - dusting shelves', 'pending');
$pendingMutationChat = $pendingMutation->chat;
$activityService->createMessage($pendingMutationChat, $bob, 'I have finished the shelves. Please approve when convenient.');
$activityService->createMessage($pendingMutationChat, $alice, "I checked them; there is still some dust on the top shelf. I'll leave this pending until it's perfect.");
$activityService->createMessage($pendingMutationChat, $bob, 'Apologies, Ma\'am. I will re-wipe the top section immediately!');
// Seed Etiquette Mutations
$activityService->createMutation($etiquetteLedger, $alice, 'penalty', 5, 'Interrupted Domina Alice during daily instructions', 'approved');
$activityService->createMutation($etiquetteLedger, $alice, 'penalty', 10, 'Forgot correct posture during morning roll call', 'approved');
$activityService->createMutation($etiquetteLedger, $alice, 'penalty', 5, 'Spoke out of turn in general chat', 'approved');
$activityService->createMutation($etiquetteLedger, $bob, 'reward', -5, 'Excellent reciting of the house codes', 'approved');
// ----------------------------------------------------
// 3. Seed Dynamic 2: Obsidian Household Agreement
// ----------------------------------------------------
$obsidianHousehold = Dynamic::create([
'name' => 'Obsidian Household Agreement',
'rules' => "1. All residents must do their fair share of maintenance.
2. Coffee machine must be refilled immediately when empty.",
]);
$obsidianHousehold->participants()->attach($alice->id, ['role' => 'owner']);
$obsidianHousehold->participants()->attach($testUser->id, ['role' => 'participant']);
$obsidianHousehold->participants()->attach($charles->id, ['role' => 'participant']);
$obsidianChat = $obsidianHousehold->chat;
$activityService->createMessage($obsidianChat, $alice, "Who finished the coffee beans and didn't put them on the shopping list?");
$activityService->createMessage($obsidianChat, $charles, "Wasn't me, I only drink tea.");
$activityService->createMessage($obsidianChat, $testUser, 'My apologies! I did refill the hopper, but forgot to list the replacement bag. I will buy a new pack tonight.');
$activityService->createMessage($obsidianChat, $alice, 'Thank you, Test User. Appreciate the honesty.');
// Add Ledgers
$kitchenLedger = Ledger::create([
'dynamic_id' => $obsidianHousehold->id,
'name' => 'Kitchen Chores',
'rules' => 'Scores for dishwashing, trash duty, and deep oven cleaning.',
'score' => 40,
'alignment' => 'positive',
]);
$coffeeLedger = Ledger::create([
'dynamic_id' => $obsidianHousehold->id,
'name' => 'Coffee Machine Maintenance',
'rules' => ' refill beans and descale monthly.',
'score' => 10,
'alignment' => 'neutral',
]);
// Seed Chores Mutations
$activityService->createMutation($kitchenLedger, $testUser, 'reward', 25, 'Emptied and loaded the dishwasher', 'approved');
$activityService->createMutation($kitchenLedger, $testUser, 'reward', 15, 'Took out recycling and trash bags', 'approved');
// Seed Coffee Mutations
$activityService->createMutation($coffeeLedger, $testUser, 'reward', 10, 'Descaled and refilled coffee beans', 'approved');
});
}
}