| 1 |
<?php |
| 2 |
namespace Booktics\Appointment\Services; |
| 3 |
|
| 4 |
use Booktics\Utils\Singleton; |
| 5 |
use WP_Error; |
| 6 |
|
| 7 |
class Appointment_Validator { |
| 8 |
|
| 9 |
use Singleton; |
| 10 |
/** |
| 11 |
* Validate data for creating an appointment. |
| 12 |
* @param array $data |
| 13 |
* @return WP_Error|null |
| 14 |
*/ |
| 15 |
public static function validate_create(array $data): ?WP_Error { |
| 16 |
if (empty($data['start_time'])) { |
| 17 |
return new WP_Error('missing_start_time', __('Start time is required', 'booktics')); |
| 18 |
} |
| 19 |
if (empty($data['end_time'])) { |
| 20 |
return new WP_Error('missing_end_time', __('End time is required', 'booktics')); |
| 21 |
} |
| 22 |
if (empty($data['date'])) { |
| 23 |
return new WP_Error('missing_date', __('Date is required', 'booktics')); |
| 24 |
} |
| 25 |
if (empty($data['service_id'])) { |
| 26 |
return new WP_Error('missing_service_id', __('Service ID is required', 'booktics')); |
| 27 |
} |
| 28 |
if (empty($data['team_member_id'])) { |
| 29 |
return new WP_Error('missing_team_member_id', __('Team member ID is required', 'booktics')); |
| 30 |
} |
| 31 |
// Add more validation as needed |
| 32 |
return null; |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* Validate data for updating an appointment. |
| 37 |
* @param array $data |
| 38 |
* @return WP_Error|null |
| 39 |
*/ |
| 40 |
public static function validate_update(array $data): ?WP_Error { |
| 41 |
if (empty($data)) { |
| 42 |
return new WP_Error('no_data', __('No data provided for update', 'booktics')); |
| 43 |
} |
| 44 |
// Optionally, check for required fields on update |
| 45 |
return null; |
| 46 |
} |
| 47 |
|
| 48 |
/** |
| 49 |
* Validate data for rescheduling an appointment. |
| 50 |
* @param array $data |
| 51 |
* @return WP_Error|null |
| 52 |
*/ |
| 53 |
public static function validate_reschedule(array $data): ?WP_Error { |
| 54 |
if (empty($data['start_time'])) { |
| 55 |
return new WP_Error('missing_start_time', __('Start time is required for reschedule', 'booktics')); |
| 56 |
} |
| 57 |
if (empty($data['end_time'])) { |
| 58 |
return new WP_Error('missing_end_time', __('End time is required for reschedule', 'booktics')); |
| 59 |
} |
| 60 |
if (empty($data['date'])) { |
| 61 |
return new WP_Error('missing_date', __('Date is required for reschedule', 'booktics')); |
| 62 |
} |
| 63 |
return null; |
| 64 |
} |
| 65 |
} |