RegisterProviderRequest.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. namespace App\Http\Requests;
  3. use App\Enums\WorkingPeriodEnum;
  4. use Illuminate\Foundation\Http\FormRequest;
  5. use Illuminate\Validation\Rule;
  6. class RegisterProviderRequest extends FormRequest
  7. {
  8. protected function prepareForValidation(): void
  9. {
  10. \Log::info('[register-provider] request chegou', [
  11. 'content_type' => $this->header('Content-Type'),
  12. 'keys' => array_keys($this->all()),
  13. 'files' => array_keys($this->allFiles()),
  14. 'has_email' => $this->has('email'),
  15. 'has_phone' => $this->has('phone'),
  16. 'has_name' => $this->has('name'),
  17. ]);
  18. }
  19. public function rules(): array
  20. {
  21. $rules = [
  22. 'email' => 'sometimes|email',
  23. 'phone' => 'sometimes|string|nullable|max:20',
  24. 'name' => 'required|string|max:255',
  25. 'code' => 'required|string|max:6',
  26. 'document' => ['required', 'string', 'max:20'],
  27. 'rg' => 'required|string|max:20',
  28. 'birth_date' => 'required|date|before:today',
  29. 'recipient_name' => 'sometimes|string|max:255',
  30. 'recipient_email' => 'sometimes|email|max:255',
  31. 'recipient_description' => 'sometimes|string',
  32. 'recipient_document' => 'sometimes|string|max:20',
  33. 'recipient_type' => ['sometimes', Rule::in(['individual', 'company'])],
  34. 'recipient_payment_mode' => ['sometimes', Rule::in(['bank_transfer'])],
  35. 'recipient_default_bank_account' => 'sometimes|array',
  36. 'recipient_default_bank_account.holder_name' => 'sometimes|string|max:255',
  37. 'recipient_default_bank_account.holder_type' => ['sometimes', Rule::in(['individual', 'company'])],
  38. 'recipient_default_bank_account.holder_document' => 'sometimes|string|max:20',
  39. 'recipient_default_bank_account.bank' => 'sometimes|string|max:3',
  40. 'recipient_default_bank_account.branch_number' => 'sometimes|string|max:20',
  41. 'recipient_default_bank_account.branch_check_digit' => 'sometimes|nullable|string|max:10',
  42. 'recipient_default_bank_account.account_number' => 'sometimes|string|max:20',
  43. 'recipient_default_bank_account.account_check_digit' => 'sometimes|string|max:10',
  44. 'recipient_default_bank_account.type' => ['sometimes', Rule::in(['checking', 'savings'])],
  45. 'recipient_default_bank_account.metadata' => 'sometimes|array',
  46. 'recipient_default_bank_account.pix_key' => 'sometimes|nullable|string|max:255',
  47. 'recipient_metadata' => 'sometimes|array',
  48. 'zip_code' => 'required|string|max:20',
  49. 'address' => 'required|string|max:255',
  50. 'has_complement' => 'sometimes|boolean',
  51. 'complement' => 'nullable|string|max:255',
  52. 'nickname' => 'nullable|string|max:255',
  53. 'instructions' => 'nullable|string',
  54. 'address_type' => ['required', Rule::in(['home', 'commercial', 'other'])],
  55. 'city' => 'nullable|string|max:255',
  56. 'state' => 'nullable|string|max:2',
  57. 'daily_price_8h' => 'required|numeric|min:100|max:500',
  58. 'daily_price_6h' => 'required|numeric|min:0',
  59. 'daily_price_4h' => 'required|numeric|min:0',
  60. 'daily_price_2h' => 'required|numeric|min:0',
  61. 'services_types_ids' => 'sometimes|array',
  62. 'services_types_ids.*' => [
  63. 'integer',
  64. Rule::exists('service_types', 'id')->where(function ($query) {
  65. $query->whereNull('deleted_at')->where('is_active', true);
  66. }),
  67. ],
  68. 'service_types_ids' => 'sometimes|array',
  69. 'service_types_ids.*' => [
  70. 'integer',
  71. Rule::exists('service_types', 'id')->where(function ($query) {
  72. $query->whereNull('deleted_at')->where('is_active', true);
  73. }),
  74. ],
  75. 'working_days' => 'required|array|min:1',
  76. 'working_days.*.day' => 'required|integer|min:0|max:6',
  77. 'working_days.*.period' => ['required', Rule::in([WorkingPeriodEnum::MORNING->value, WorkingPeriodEnum::AFTERNOON->value])],
  78. 'selfie' => 'required|file|image|mimes:jpg,jpeg,png,webp|max:5120',
  79. 'document_front' => 'required|file|image|mimes:jpg,jpeg,png,webp|max:10240',
  80. 'document_back' => 'required|file|image|mimes:jpg,jpeg,png,webp|max:10240',
  81. ];
  82. if (!$this->has('email')) {
  83. $rules['phone'] = 'required|string|max:20';
  84. $rules['email'] = 'nullable';
  85. }
  86. if (!$this->has('phone')) {
  87. $rules['email'] = 'required|email';
  88. $rules['phone'] = 'nullable';
  89. }
  90. return $rules;
  91. }
  92. }