Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
UserRolePlaySettings
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 forUser
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace App\Http\Models;
4
5/**
6 * UserRolePlaySettings Model
7 *
8 * Stores per-user default preferences for roleplay sessions,
9 * including default call type, difficulty, focus sections,
10 * scorecard overrides, and UI preferences.
11 *
12 * @property string $user_id The user's ID
13 * @property string $default_call_type Default call type (e.g., 'cold-call', 'discovery-call')
14 * @property int $default_difficulty Default difficulty level (1-5)
15 * @property array<string> $focus_sections Array of section names to focus on
16 * @property array|null $scorecard_override Custom scorecard override configuration (legacy, kept for backward compat)
17 * @property array $scorecard_config Per-call-type scorecard overrides: ['cold-call' => ScorecardConfig[], 'discovery-call' => ScorecardConfig[]]
18 * @property array $ui_preferences UI display preferences (e.g., show_radar, show_timeline)
19 * @property \Carbon\Carbon|null $created_at
20 * @property \Carbon\Carbon|null $updated_at
21 */
22class UserRolePlaySettings extends Moloquent
23{
24    /**
25     * The database table used by the model.
26     *
27     * @var string
28     */
29    protected $table = 'user_role_play_settings';
30
31    /**
32     * The attributes that are mass assignable.
33     *
34     * @var array<int, string>
35     */
36    protected $fillable = [
37        'user_id',
38        'default_call_type',
39        'default_difficulty',
40        'focus_sections',
41        'scorecard_override',
42        'scorecard_config',
43        'ui_preferences',
44    ];
45
46    /**
47     * The attributes that should be cast.
48     *
49     * @var array<string, string>
50     */
51    protected $casts = [
52        'focus_sections'     => 'array',
53        'scorecard_override' => 'array',
54        'scorecard_config'   => 'array',
55        'ui_preferences'     => 'array',
56    ];
57
58    /**
59     * Retrieve or create default settings for a given user.
60     *
61     * @param string $userId The user's ID
62     * @return self
63     */
64    public static function forUser(string $userId): self
65    {
66        return static::firstOrCreate(
67            ['user_id' => $userId],
68            [
69                'default_call_type'  => 'cold-call',
70                'default_difficulty' => 3,
71                'focus_sections'     => [],
72                'scorecard_override' => null,
73                'scorecard_config'   => [],
74                'ui_preferences'     => ['show_radar' => true, 'show_timeline' => true],
75            ]
76        );
77    }
78}