CustomScheduleService.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  1. <?php
  2. namespace App\Services;
  3. use App\Enums\NotificationTypeEnum;
  4. use App\Models\Address;
  5. use App\Models\CustomSchedule;
  6. use App\Models\CustomScheduleSpeciality;
  7. use App\Models\Provider;
  8. use App\Models\Schedule;
  9. use App\Models\ScheduleProposal;
  10. use App\Models\ScheduleRefuse;
  11. use App\Rules\ScheduleBusinessRules;
  12. use App\Services\NotificationService;
  13. use Carbon\Carbon;
  14. use Illuminate\Support\Facades\DB;
  15. use Illuminate\Support\Facades\Log;
  16. use Illuminate\Support\Facades\Storage;
  17. class CustomScheduleService
  18. {
  19. public function __construct() {}
  20. public function getAll()
  21. {
  22. $custom_schedules = CustomSchedule::with([
  23. 'schedule.client.user',
  24. 'schedule.address',
  25. 'serviceType',
  26. 'specialities.speciality',
  27. ])
  28. ->orderBy('id', 'desc')
  29. ->get();
  30. return $custom_schedules;
  31. }
  32. public function getById($id)
  33. {
  34. $customSchedule = CustomSchedule::with([
  35. 'schedule.client.user',
  36. 'schedule.client.profileMedia',
  37. 'schedule.address',
  38. 'serviceType',
  39. 'specialities.speciality',
  40. ])->find($id);
  41. return $customSchedule;
  42. }
  43. public function create(array $data)
  44. {
  45. DB::beginTransaction();
  46. try {
  47. $quantity = $data['quantity'] ?? 1;
  48. $specialityIds = $data['speciality_ids'] ?? [];
  49. $createdCustomSchedules = [];
  50. for ($i = 0; $i < $quantity; $i++) {
  51. $scheduleData = [
  52. 'client_id' => $data['client_id'],
  53. 'provider_id' => null,
  54. 'address_id' => $data['address_id'],
  55. 'date' => $data['date'],
  56. 'period_type' => $data['period_type'],
  57. 'schedule_type' => 'custom',
  58. 'start_time' => $data['start_time'],
  59. 'end_time' => $data['end_time'],
  60. 'status' => 'pending',
  61. 'total_amount' => 0,
  62. 'code' => str_pad(random_int(0, 9999), 4, '0', STR_PAD_LEFT),
  63. 'code_verified' => false,
  64. ];
  65. $schedule = Schedule::create($scheduleData);
  66. $customScheduleData = [
  67. 'schedule_id' => $schedule->id,
  68. 'address_type' => $data['address_type'],
  69. 'service_type_id' => $data['service_type_id'],
  70. 'description' => $data['description'] ?? null,
  71. 'min_price' => $data['min_price'],
  72. 'max_price' => $data['max_price'],
  73. 'offers_meal' => $data['offers_meal'] ?? false,
  74. ];
  75. $customSchedule = CustomSchedule::create($customScheduleData);
  76. if (! empty($specialityIds)) {
  77. foreach ($specialityIds as $specialityId) {
  78. CustomScheduleSpeciality::create([
  79. 'custom_schedule_id' => $customSchedule->id,
  80. 'speciality_id' => $specialityId,
  81. ]);
  82. }
  83. }
  84. $createdCustomSchedules[] = $customSchedule->load([
  85. 'schedule.client.user',
  86. 'schedule.address',
  87. 'serviceType',
  88. 'specialities.speciality',
  89. ]);
  90. }
  91. DB::commit();
  92. return $createdCustomSchedules;
  93. } catch (\Exception $e) {
  94. DB::rollBack();
  95. Log::error('Error creating custom schedule: '.$e->getMessage());
  96. throw $e;
  97. }
  98. }
  99. public function update($id, array $data)
  100. {
  101. DB::beginTransaction();
  102. try {
  103. $customSchedule = CustomSchedule::findOrFail($id);
  104. $schedule = $customSchedule->schedule;
  105. $scheduleUpdateData = [];
  106. if (isset($data['address_id'])) {
  107. $scheduleUpdateData['address_id'] = $data['address_id'];
  108. }
  109. if (isset($data['date'])) {
  110. $scheduleUpdateData['date'] = $data['date'];
  111. }
  112. if (isset($data['period_type'])) {
  113. $scheduleUpdateData['period_type'] = $data['period_type'];
  114. }
  115. if (isset($data['start_time'])) {
  116. $scheduleUpdateData['start_time'] = $data['start_time'];
  117. }
  118. if (isset($data['end_time'])) {
  119. $scheduleUpdateData['end_time'] = $data['end_time'];
  120. }
  121. if (! empty($scheduleUpdateData)) {
  122. $schedule->update($scheduleUpdateData);
  123. }
  124. $customScheduleUpdateData = [];
  125. if (isset($data['address_type'])) {
  126. $customScheduleUpdateData['address_type'] = $data['address_type'];
  127. }
  128. if (isset($data['service_type_id'])) {
  129. $customScheduleUpdateData['service_type_id'] = $data['service_type_id'];
  130. }
  131. if (isset($data['description'])) {
  132. $customScheduleUpdateData['description'] = $data['description'];
  133. }
  134. if (isset($data['min_price'])) {
  135. $customScheduleUpdateData['min_price'] = $data['min_price'];
  136. }
  137. if (isset($data['max_price'])) {
  138. $customScheduleUpdateData['max_price'] = $data['max_price'];
  139. }
  140. if (isset($data['offers_meal'])) {
  141. $customScheduleUpdateData['offers_meal'] = $data['offers_meal'];
  142. }
  143. if (! empty($customScheduleUpdateData)) {
  144. $customSchedule->update($customScheduleUpdateData);
  145. }
  146. if (isset($data['speciality_ids'])) {
  147. $custom_schedule = CustomScheduleSpeciality::where('custom_schedule_id', $customSchedule->id);
  148. $custom_schedule->delete();
  149. foreach ($data['speciality_ids'] as $specialityId) {
  150. CustomScheduleSpeciality::create([
  151. 'custom_schedule_id' => $customSchedule->id,
  152. 'speciality_id' => $specialityId,
  153. ]);
  154. }
  155. }
  156. DB::commit();
  157. return $customSchedule->fresh([
  158. 'schedule.client.user',
  159. 'schedule.address',
  160. 'serviceType',
  161. 'specialities.speciality',
  162. ]);
  163. } catch (\Exception $e) {
  164. DB::rollBack();
  165. Log::error('Error updating custom schedule: '.$e->getMessage());
  166. throw $e;
  167. }
  168. }
  169. public function delete($id)
  170. {
  171. DB::beginTransaction();
  172. try {
  173. $customSchedule = CustomSchedule::findOrFail($id);
  174. $schedule = $customSchedule->schedule;
  175. CustomScheduleSpeciality::where('custom_schedule_id', $customSchedule->id)->delete();
  176. $customSchedule->delete();
  177. $schedule->delete();
  178. DB::commit();
  179. return $customSchedule;
  180. } catch (\Exception $e) {
  181. DB::rollBack();
  182. Log::error('Error deleting custom schedule: '.$e->getMessage());
  183. throw $e;
  184. }
  185. }
  186. public function getSchedulesCustomGroupedByClient()
  187. {
  188. $schedules = Schedule::with(['client.user', 'provider.user', 'address', 'customSchedule.serviceType', 'customSchedule.specialities', 'reviews.reviewsImprovements.improvementType'])
  189. ->orderBy('id', 'desc')
  190. ->where('schedule_type', 'custom')
  191. ->get();
  192. $grouped = $this->formatCustomSchedules($schedules);
  193. return $grouped;
  194. }
  195. public function getAvailableOpportunities($providerId)
  196. {
  197. $provider = Provider::find($providerId);
  198. $providerAddress = Address::where('source', 'provider')
  199. ->where('source_id', $providerId)
  200. ->orderBy('is_primary', 'desc')
  201. ->first();
  202. $providerLat = $providerAddress?->latitude !== null ? (float) $providerAddress->latitude : null;
  203. $providerLng = $providerAddress?->longitude !== null ? (float) $providerAddress->longitude : null;
  204. $opportunities = Schedule::with([
  205. 'client.user',
  206. 'client.profileMedia',
  207. 'address',
  208. 'customSchedule.serviceType',
  209. 'customSchedule.specialities',
  210. ])
  211. ->leftJoin('schedule_refuses', function ($join) use ($providerId) {
  212. $join->on('schedules.id', '=', 'schedule_refuses.schedule_id')
  213. ->where('schedule_refuses.provider_id', $providerId);
  214. })
  215. ->whereNull('schedule_refuses.id')
  216. ->where('schedules.schedule_type', 'custom')
  217. ->where('schedules.status', 'pending')
  218. ->whereNull('schedules.provider_id')
  219. ->whereDate('schedules.date', '>=', now()->toDateString())
  220. ->select(
  221. 'schedules.id',
  222. 'schedules.client_id',
  223. 'schedules.address_id',
  224. 'schedules.date',
  225. 'schedules.period_type',
  226. 'schedules.start_time',
  227. 'schedules.end_time',
  228. 'schedules.total_amount',
  229. DB::raw("CASE
  230. WHEN schedules.period_type = '2' THEN {$provider->daily_price_2h}
  231. WHEN schedules.period_type = '4' THEN {$provider->daily_price_4h}
  232. WHEN schedules.period_type = '6' THEN {$provider->daily_price_6h}
  233. WHEN schedules.period_type = '8' THEN {$provider->daily_price_8h}
  234. ELSE 0
  235. END as total_amount"),
  236. )
  237. ->get();
  238. $availableOpportunities = $opportunities->filter(function ($opportunity) use ($providerId) {
  239. try {
  240. return $this->checkProviderAvailability($providerId, $opportunity);
  241. } catch (\Exception $e) {
  242. return false;
  243. }
  244. });
  245. $availableOpportunities->each(function ($opportunity) use ($providerLat, $providerLng) {
  246. $opportunity->distance_km = DistanceService::calculate(
  247. $providerLat,
  248. $providerLng,
  249. $opportunity->address?->latitude !== null ? (float) $opportunity->address->latitude : null,
  250. $opportunity->address?->longitude !== null ? (float) $opportunity->address->longitude : null,
  251. );
  252. $photoPath = $opportunity->client->profileMedia?->path;
  253. $opportunity->customer_photo = $photoPath
  254. ? Storage::temporaryUrl($photoPath, now()->addMinutes(60))
  255. : null;
  256. });
  257. return $availableOpportunities->values();
  258. }
  259. public function getProviderProposals($providerId)
  260. {
  261. return ScheduleProposal::with([
  262. 'schedule.client.user',
  263. 'schedule.address',
  264. 'schedule.address.city',
  265. 'schedule.address.state',
  266. 'schedule.customSchedule.serviceType',
  267. 'schedule.customSchedule.specialities',
  268. 'schedule.provider.user',
  269. ])
  270. ->where('provider_id', $providerId)
  271. ->orderBy('created_at', 'desc')
  272. ->get();
  273. }
  274. public function getOpportunityProposals($scheduleId)
  275. {
  276. return ScheduleProposal::with(['provider.user'])
  277. ->where('schedule_id', $scheduleId)
  278. ->orderBy('created_at', 'desc')
  279. ->get();
  280. }
  281. public function proposeOpportunity($scheduleId, $providerId)
  282. {
  283. $schedule = Schedule::findOrFail($scheduleId);
  284. if ($schedule->provider_id) {
  285. throw new \Exception(__('validation.custom.opportunity.already_assigned'));
  286. }
  287. $existingProposal = ScheduleProposal::where('schedule_id', $scheduleId)
  288. ->where('provider_id', $providerId)
  289. ->first();
  290. if ($existingProposal) {
  291. throw new \Exception(__('validation.custom.opportunity.proposal_already_sent'));
  292. }
  293. $wasRefused = ScheduleRefuse::where('schedule_id', $scheduleId)
  294. ->where('provider_id', $providerId)
  295. ->exists();
  296. if ($wasRefused) {
  297. throw new \Exception(__('validation.custom.opportunity.provider_refused'));
  298. }
  299. $this->checkProviderAvailability($providerId, $schedule);
  300. $provider = Provider::with([
  301. 'user'
  302. ])->findOrFail($providerId);
  303. $schedule->load([
  304. 'client.user'
  305. ]);
  306. $notificationService = app(NotificationService::class);
  307. $notificationService->create([
  308. 'title' => 'Nova proposta recebida!',
  309. 'description' =>
  310. $provider->user->name .
  311. ' enviou uma proposta para seu agendamento sob medida.',
  312. 'origin' => 'schedule',
  313. 'origin_id' => $schedule->id,
  314. 'type' => NotificationTypeEnum::SCHEDULE_PROVIDER_CLIENT_NEW_SOLICITATION->value,
  315. 'user_id' => $schedule->client->user_id,
  316. ]);
  317. return ScheduleProposal::create([
  318. 'schedule_id' => $scheduleId,
  319. 'provider_id' => $providerId,
  320. ]);
  321. }
  322. public function acceptProposal($proposalId)
  323. {
  324. return DB::transaction(function () use ($proposalId) {
  325. $proposal = ScheduleProposal::findOrFail($proposalId);
  326. $schedule = $proposal->schedule;
  327. if ($schedule->provider_id) {
  328. throw new \Exception(__('validation.custom.opportunity.already_assigned'));
  329. }
  330. $provider = Provider::find($proposal->provider_id);
  331. switch ($schedule->period_type) {
  332. case '8':
  333. $baseAmount = $provider->daily_price_8h;
  334. break;
  335. case '6':
  336. $baseAmount = $provider->daily_price_6h;
  337. break;
  338. case '4':
  339. $baseAmount = $provider->daily_price_4h;
  340. break;
  341. case '2':
  342. $baseAmount = $provider->daily_price_2h;
  343. break;
  344. default:
  345. throw new \Exception('Periodo do agendamento invalido.');
  346. }
  347. $schedule->total_amount = $baseAmount;
  348. $schedule->save();
  349. $schedule->update([
  350. 'provider_id' => $proposal->provider_id,
  351. ]);
  352. $schedule->refresh();
  353. $schedule->load(['provider.user', 'client.user']);
  354. $notificationService->create([
  355. 'title' => 'Proposta aceita!',
  356. 'description' => 'O cliente aceitou sua proposta de diária.',
  357. 'origin' => 'schedule',
  358. 'origin_id' => $schedule->id,
  359. 'type' => NotificationTypeEnum::SCHEDULE_PROVIDER_CLIENT_PROPOSAL_ACCEPTED->value,
  360. 'user_id' => $provider->user_id,
  361. ]);
  362. app(ScheduleService::class)->updateStatus($schedule->id, 'accepted');
  363. ScheduleProposal::where('schedule_id', $schedule->id)
  364. ->where('id', '!=', $proposalId)
  365. ->delete();
  366. return $schedule->fresh(['provider.user']);
  367. });
  368. }
  369. public function refuseProposal($proposalId)
  370. {
  371. return DB::transaction(function () use ($proposalId) {
  372. $proposal = ScheduleProposal::findOrFail($proposalId);
  373. ScheduleRefuse::create([
  374. 'schedule_id' => $proposal->schedule_id,
  375. 'provider_id' => $proposal->provider_id,
  376. ]);
  377. $notificationService = app(NotificationService::class);
  378. $notificationService->create([
  379. 'title' => 'Proposta recusada!',
  380. 'description' =>
  381. 'O cliente recusou sua proposta de diária.',
  382. 'origin' => 'schedule',
  383. 'origin_id' => $proposal->schedule_id,
  384. 'type' =>
  385. NotificationTypeEnum::SCHEDULE_CLIENT_PROVIDER_REFUSED->value,
  386. 'user_id' => $proposal->provider->user_id,
  387. ]);
  388. $proposal->delete();
  389. return true;
  390. });
  391. }
  392. private function checkProviderAvailability($providerId, $schedule)
  393. {
  394. $client_id = $schedule->client_id;
  395. $provider_id = $providerId;
  396. $date = Carbon::parse($schedule->date);
  397. $dayOfWeek = $date->dayOfWeek; // 0-6
  398. $startTime = $schedule->start_time;
  399. $endTime = $schedule->end_time;
  400. $date_ymd = $date->format('Y-m-d');
  401. $period = $startTime < '13:00:00' ? 'morning' : 'afternoon';
  402. $period_type = $schedule->period_type; // 2,4,6,8
  403. // bloqueio 2 schedules por semana para o mesmo client e provider
  404. ScheduleBusinessRules::validateWeeklyScheduleLimit(
  405. $client_id,
  406. $provider_id,
  407. $date_ymd
  408. );
  409. // bloqueio provider trabalha no dia/periodo
  410. ScheduleBusinessRules::validateWorkingDay(
  411. $provider_id,
  412. $dayOfWeek,
  413. $period
  414. );
  415. // bloqueio provider tem blockedday para dia/hora
  416. ScheduleBusinessRules::validateBlockedDay(
  417. $provider_id,
  418. $date_ymd,
  419. $startTime,
  420. $endTime
  421. );
  422. // bloqueio daily_price do provider esta fora do range min_price e max_price
  423. ScheduleBusinessRules::validatePricePeriod(
  424. $provider_id,
  425. $schedule->customSchedule->min_price,
  426. $schedule->customSchedule->max_price,
  427. $period_type
  428. );
  429. // bloqueio provider tem outro agendamento para dia/hora
  430. ScheduleBusinessRules::validateConflictingSchedule(
  431. $provider_id,
  432. $date_ymd,
  433. $startTime,
  434. $endTime
  435. );
  436. // bloqueio provider tem outra proposta para o mesmo agendamento
  437. ScheduleBusinessRules::validateConflictingSameProposal(
  438. $provider_id,
  439. $schedule->id
  440. );
  441. // bloqueio provider tem outra proposta na mesma data
  442. ScheduleBusinessRules::validateConflictingProposalSameDate(
  443. $provider_id,
  444. $date_ymd,
  445. $startTime,
  446. $endTime,
  447. $schedule->id
  448. );
  449. // bloqueio caso o client tenha bloqueado o provider
  450. ScheduleBusinessRules::validateClientNotBlockedByProvider(
  451. $client_id,
  452. $provider_id
  453. );
  454. // bloqueio caso o provider tenha bloqueado o client
  455. ScheduleBusinessRules::validateProviderNotBlockedByClient(
  456. $client_id,
  457. $provider_id
  458. );
  459. return true;
  460. }
  461. public function getProvidersProposalsAndOpportunities($providerId)
  462. {
  463. $proposals = $this->getProviderProposals($providerId);
  464. $opportunities = $this->formatCustomSchedules($this->getAvailableOpportunities($providerId));
  465. return [
  466. 'proposals' => $proposals,
  467. 'opportunities' => $opportunities,
  468. ];
  469. }
  470. public function formatCustomSchedules($schedules)
  471. {
  472. $grouped = $schedules->groupBy('client_id')->map(function ($clientSchedules) {
  473. $firstSchedule = $clientSchedules->first();
  474. $clientPhotoPath = $firstSchedule->client->profileMedia?->path;
  475. return [
  476. 'client_id' => $firstSchedule->client_id,
  477. 'client_name' => $firstSchedule->client->user->name ?? 'N/A',
  478. 'customer_photo' => $clientPhotoPath
  479. ? Storage::temporaryUrl($clientPhotoPath, now()->addMinutes(60))
  480. : null,
  481. 'schedules' => $clientSchedules->map(function ($schedule) {
  482. $customSchedule = $schedule->customSchedule;
  483. return [
  484. 'id' => $schedule->id,
  485. 'date' => $schedule->date ? Carbon::parse($schedule->date)->format('d/m/Y') : null,
  486. 'start_time' => $schedule->start_time,
  487. 'end_time' => $schedule->end_time,
  488. 'period_type' => $schedule->period_type,
  489. 'status' => $schedule->status,
  490. 'total_amount' => $schedule->total_amount,
  491. 'code' => $schedule->code,
  492. 'code_verified' => $schedule->code_verified,
  493. 'provider_id' => $schedule->provider_id,
  494. 'client_id' => $schedule->client_id,
  495. 'provider_name' => $schedule->provider?->user->name ?? 'N/A',
  496. 'address' => $schedule->address ? [
  497. 'id' => $schedule->address->id,
  498. 'address' => $schedule->address->address,
  499. 'complement' => $schedule->address->complement,
  500. 'zip_code' => $schedule->address->zip_code,
  501. 'city' => $schedule->address->city->name ?? '',
  502. 'state' => $schedule->address->city->state->name ?? '',
  503. ] : null,
  504. 'client_name' => $schedule->client->user->name ?? 'N/A',
  505. 'custom_schedule' => $customSchedule ? [
  506. 'id' => $customSchedule->id,
  507. 'address_type' => $customSchedule->address_type,
  508. 'service_type_id' => $customSchedule->service_type_id,
  509. 'service_type_name' => $customSchedule->serviceType?->description ?? 'N/A',
  510. 'description' => $customSchedule->description,
  511. 'min_price' => $customSchedule->min_price,
  512. 'max_price' => $customSchedule->max_price,
  513. 'offers_meal' => $customSchedule->offers_meal,
  514. 'specialities' => $customSchedule->specialities->map(function ($speciality) {
  515. return [
  516. 'id' => $speciality->id,
  517. 'description' => $speciality->description,
  518. ];
  519. })->values(),
  520. ] : null,
  521. 'reviews' => $schedule->reviews->map(function ($review) {
  522. return [
  523. 'id' => $review->id,
  524. 'stars' => $review->stars,
  525. 'comment' => $review->comment,
  526. 'origin' => $review->origin,
  527. 'origin_id' => $review->origin_id,
  528. 'created_at' => Carbon::parse($review->created_at)->format('Y-m-d H:i'),
  529. 'updated_at' => Carbon::parse($review->updated_at)->format('Y-m-d H:i'),
  530. 'improvements' => $review->reviewsImprovements->map(function ($ri) {
  531. return [
  532. 'id' => $ri->id,
  533. 'improvement_type_id' => $ri->improvement_type_id,
  534. 'improvement_type_name' => $ri->improvementType ? $ri->improvementType->description : null,
  535. ];
  536. })->values(),
  537. ];
  538. }),
  539. ];
  540. })->values(),
  541. ];
  542. })->sortBy('id')->values();
  543. return $grouped;
  544. }
  545. public function verifyScheduleCode($scheduleId, $code)
  546. {
  547. $schedule = Schedule::findOrFail($scheduleId);
  548. if ($schedule->code_verified) {
  549. throw new \Exception(__('validation.custom.opportunity.code_already_verified'));
  550. }
  551. if ($schedule->code !== $code) {
  552. throw new \Exception(__('validation.custom.opportunity.invalid_code'));
  553. }
  554. $schedule->update([
  555. 'code_verified' => true,
  556. ]);
  557. return $schedule;
  558. }
  559. public function refuseOpportunity($scheduleId, $providerId)
  560. {
  561. $schedule = Schedule::with(['client.user'])->findOrFail($scheduleId);
  562. $provider = Provider::with(['user'])->findOrFail($providerId);
  563. $schedule_refuse = ScheduleRefuse::create([
  564. 'schedule_id' => $scheduleId,
  565. 'provider_id' => $providerId,
  566. ]);
  567. $notificationService = app(NotificationService::class);
  568. $notificationService->create([
  569. 'title' => 'Oportunidade recusada!',
  570. 'description' => $provider->user->name . ' recusou sua solicitação sob medida.',
  571. 'origin' => 'schedule',
  572. 'origin_id' => $scheduleId,
  573. 'type' =>
  574. NotificationTypeEnum::SCHEDULE_CLIENT_PROVIDER_REFUSED->value,
  575. 'user_id' => $schedule->client->user_id,
  576. ]);
  577. return $schedule_refuse;
  578. }
  579. }