Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
13 / 13 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
| CompanyRolePlayScorecardService | |
100.00% |
13 / 13 |
|
100.00% |
5 / 5 |
5 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| listForCompany | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| findForCompanyAndCallType | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| upsertForCompanyAndCallType | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
1 | |||
| deleteForCompanyAndCallType | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Http\Services; |
| 4 | |
| 5 | use App\Http\Models\CompanyRolePlayScorecard; |
| 6 | use App\Http\Repositories\interfaces\ICompanyRolePlayScorecardRepository; |
| 7 | use Illuminate\Support\Collection; |
| 8 | |
| 9 | /** |
| 10 | * Service for company-level RolePlay scorecard configuration. |
| 11 | * |
| 12 | * Encapsulates the business rules that sit on top of raw persistence |
| 13 | * (upsert semantics, deletion reporting) so controllers stay thin. |
| 14 | */ |
| 15 | class CompanyRolePlayScorecardService |
| 16 | { |
| 17 | public function __construct( |
| 18 | private readonly ICompanyRolePlayScorecardRepository $scorecardRepository, |
| 19 | ) {} |
| 20 | |
| 21 | /** |
| 22 | * @return Collection<int, CompanyRolePlayScorecard> |
| 23 | */ |
| 24 | public function listForCompany(string $companyId): Collection |
| 25 | { |
| 26 | return $this->scorecardRepository->listForCompany($companyId); |
| 27 | } |
| 28 | |
| 29 | public function findForCompanyAndCallType(string $companyId, string $callType): ?CompanyRolePlayScorecard |
| 30 | { |
| 31 | return $this->scorecardRepository->findForCompanyAndCallType($companyId, $callType); |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Upsert the company scorecard configuration for a given call type. |
| 36 | * |
| 37 | * @param array<int, array<string, mixed>> $scorecard ScorecardConfig array. |
| 38 | */ |
| 39 | public function upsertForCompanyAndCallType( |
| 40 | string $companyId, |
| 41 | string $callType, |
| 42 | array $scorecard, |
| 43 | bool $isForced, |
| 44 | string $createdBy, |
| 45 | ): CompanyRolePlayScorecard { |
| 46 | return $this->scorecardRepository->upsertForCompanyAndCallType( |
| 47 | $companyId, |
| 48 | $callType, |
| 49 | [ |
| 50 | 'scorecard' => $scorecard, |
| 51 | 'is_forced' => $isForced, |
| 52 | 'created_by' => $createdBy, |
| 53 | ], |
| 54 | ); |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Returns true if a row was deleted, false if none existed. |
| 59 | */ |
| 60 | public function deleteForCompanyAndCallType(string $companyId, string $callType): bool |
| 61 | { |
| 62 | return $this->scorecardRepository->deleteForCompanyAndCallType($companyId, $callType); |
| 63 | } |
| 64 | } |