*/ class ArcadiaMailGame extends ClientModel { /** * An RFC Valid Email * * Validate: rfc,dns,spoof,filter * * Required * Min length N/A * Max length 255 * Field Type varchar * * @var string|null */ private ?string $email = null; /** * First name * * Required * Min length 2 * Max length 255 * Field Type varchar * * @var string|null */ private ?string $firstname = null; /** * Last name * * Required * Min length 2 * Max length 255 * Field Type varchar * * @var string|null */ private ?string $lastname = null; /** * The user phone * * Validate: sometimes,string * * Required * Min length NA * Max length 255 * Field Type varchar * * @var string|null */ private ?string $phone = null; /** * The user address (street number, name, etc) * * Validate: sometimes,string * * Min length NA * Max length 255 * Field Type varchar * * @var string|null */ private ?string $address = null; /** * The user address 2nd part (street number, name, more, etc) * * Validate: sometimes,string * * Min length NA * Max length 255 * Field Type varchar * * @var string|null */ private ?string $address2 = null; /** * The user address city * * Validate: sometimes,string * * Min length NA * Max length 255 * Field Type varchar * * @var string|null */ private ?string $city = null; /** * The user address postcode * * Validate: string * * Required * Min length NA * Max length 255 * Field Type varchar * * @var string|null */ private ?string $postcode = null; /** * The arcadia operation code * * Validate: int * * Required * * @var integer|null */ private ?int $operation = null; /** * The arcadia support code * * Validate: int * * Required * * @var integer|null */ private ?int $support_code = null; /** * The arcadia type support label * * Validate: string * * Required * * @var string|null */ private ?string $label_type_support = null; /** * The arcadia order date * * Validate: date * * Required * * @var string|null */ private ?string $order_date = null; /** * The arcadia code unique * * Validate: string * * Required * * @var string|null */ private ?string $code_unique = null; /** * The arcadia code on pack * * Validate: sometimes * * Required * * @var string|null */ private ?string $code_on_pack = null; /** * The crm customer fields * * @var array */ protected array $modelFields = [ 'email', 'firstname', 'lastname', 'phone', 'address', 'address2', 'city', 'postcode', 'operation', 'support_code', 'label_type_support', 'order_date', 'code_unique', 'code_on_pack', ]; /** * Validation rules * * @var array */ protected static array $validation = [ 'email' => 'required|email', 'firstname' => 'required|string|min:2|max:255', 'lastname' => 'required|string|min:2|max:255', 'phone' => 'sometimes|string|min:10|max:255', 'address' => 'sometimes|string|max:255', 'address2' => 'sometimes|string|max:255', 'city' => 'sometimes|string|max:255', 'postcode' => 'sometimes|string|max:255', 'operation' => 'required|int', 'support_code' => 'required|int', 'label_type_support' => 'required|string|min:2|max:255', 'order_date' => 'required|date_format:Y/m/d H:i:s', 'code_unique' => 'required|string', 'code_on_pack' => 'sometimes|string' ]; /** * ArcadiaMailGame * * @param array $properties * @throws \LDC\LDCCRM\Exceptions\ValidationException If a field could not be validated. */ public function __construct(array $properties = []) { parent::__construct(); $this->fill($properties); return $this; } /** * Set prop * * @param string $field * @param mixed $value * @return void * @throws \TypeError If the field has an incorrect value. * @throws \LDC\LDCCRM\Exceptions\AccessError If trying to set a value on a unknown property. */ public function __set(string $field, mixed $value): void { if ($field === 'state_order') { $value = (\is_object($value) and get_class($value) === ArcadiaOrderType::class) ? $value->value() : $value; } parent::__set($field, $value); } /** * Fill data into this model * using validation rules * * @param array $properties * @return void * @throws \LDC\LDCCRM\Exceptions\ValidationException If a field could not be validated. */ public function fill(array $properties) { if (isset($properties['state_order'])) { try { $properties['state_order'] = (\is_object($properties['state_order']) and get_class($properties['state_order']) === ArcadiaOrderType::class) ? $properties['state_order']->value : (ctype_digit($properties['state_order']) ? (int)$properties['state_order'] : $properties['state_order']); } catch (\TypeError | \BadMethodCallException) { // * Cast anyway $properties['state_order'] = (int)$properties['state_order']; } } parent::fill($properties); } // * PUBLIC METHODS /** * Send The actual mail * * @return boolean true if succeeded * @throws \LDC\LDCCRM\Exceptions\CrmException If an error occurs on server side or on getting response. * @throws \LDC\LDCCRM\Exceptions\ApiErrorException If any error or \LDC\LDCCRM\Enums\ApiError occurs. * Possibles are : - validationFailed, If provided data is wrong(CRM side). */ public function send(): bool { $this->validateAllValues(); static::setUpApiInterface(); $request = Utils::getResquest('apiV4.arcadia.outgoingMailGame', [], $this->jsonSerialize()); $response = static::$apiInterface->call($request); if ($status = $response->status->equals(ApiStatus::OK)) { $this->updatedValues = []; } $this->isNew = !$status; return $status; } /** * Serialize this object to an array * * @return array */ public function jsonSerialize() { return [ 'deliver' => [ 'email' => $this->email, 'firstname' => $this->firstname, 'lastname' => $this->lastname, 'phone' => $this->phone, 'address' => $this->address, 'address2' => $this->address2, 'city' => $this->city, 'postcode' => $this->postcode, ], 'operation' => $this->operation, 'support_code' => $this->support_code, 'label_type_support' => $this->label_type_support, 'order_date' => $this->order_date, 'code_unique' => $this->code_unique, 'code_on_pack' => $this->code_on_pack ]; } }