ldc-crm-client/src/Models/ArcadiaMailGame.php

360 lines
9.2 KiB
PHP
Raw Normal View History

<?php
namespace LDC\LDCCRM\Models;
use LDC\LDCCRM\Enums\ApiStatus;
use LDC\LDCCRM\Enums\ArcadiaOrderType;
use LDC\LDCCRM\Utils;
/**
* This class represents the customer info with
* the account validation status
*
2023-10-05 12:16:43 +02:00
* @property integer $operation The arcadia operation code
* Validate: int
* Required
*
2023-09-15 12:11:28 +02:00
* @property string|null $email Must be a rfc valid email on a valid domain name
* @property string|null $firstname The account first name
* @property string|null $lastname The account last name
* @property string|null $phone The account phone
* @property string|null $address The account address (street number, name, build, flat number)
* @property string|null $address2 The account phone (address complement)
* @property string|null $city The account city name
* @property string|null $postcode The account city postcode
*
2023-10-05 12:16:43 +02:00
* @property integer|null $support_code The arcadia support code
* @property string|null $label_type_support The arcadia type support label
* @property string|null $order_date The arcadia order date 'yyyy-mm-dd HH:ii:ss'
* @property string|null $code_unique The arcadia code unique
* @property string|null $code_on_pack The arcadia code on pack
*
* @category Api Models
* @package LDCCrmClient
* @subpackage models
* @author Jérémy Munsch <jeremy.munsch@ldc.fr>
*/
2023-10-05 12:16:43 +02:00
class ArcadiaMailGame extends ClientModel
{
/**
* An RFC Valid Email
*
* Validate: rfc,dns,spoof,filter
*
* Required
* Min length N/A
* Max length 255
* Field Type varchar
*
2023-09-15 12:11:28 +02:00
* @var string|null
*/
2023-09-15 12:11:28 +02:00
private ?string $email = null;
/**
* First name
*
* Required
* Min length 2
* Max length 255
* Field Type varchar
*
2023-09-15 12:11:28 +02:00
* @var string|null
*/
2023-09-15 12:11:28 +02:00
private ?string $firstname = null;
/**
* Last name
*
* Required
* Min length 2
* Max length 255
* Field Type varchar
*
2023-09-15 12:11:28 +02:00
* @var string|null
*/
2023-09-15 12:11:28 +02:00
private ?string $lastname = null;
/**
* The user phone
*
* Validate: sometimes,string
*
* Required
* Min length NA
* Max length 255
* Field Type varchar
*
2023-09-15 12:11:28 +02:00
* @var string|null
*/
2023-09-15 12:11:28 +02:00
private ?string $phone = null;
/**
* The user address (street number, name, etc)
*
* Validate: sometimes,string
*
* Min length NA
* Max length 255
* Field Type varchar
*
2023-09-15 12:11:28 +02:00
* @var string|null
*/
2023-09-15 12:11:28 +02:00
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
*
2023-09-15 12:11:28 +02:00
* @var string|null
*/
2023-09-15 12:11:28 +02:00
private ?string $address2 = null;
/**
* The user address city
*
* Validate: sometimes,string
*
* Min length NA
* Max length 255
* Field Type varchar
*
2023-09-15 12:11:28 +02:00
* @var string|null
*/
2023-09-15 12:11:28 +02:00
private ?string $city = null;
/**
* The user address postcode
*
* Validate: string
*
* Required
* Min length NA
* Max length 255
* Field Type varchar
*
2023-09-15 12:11:28 +02:00
* @var string|null
*/
2023-09-15 12:11:28 +02:00
private ?string $postcode = null;
/**
* The arcadia operation code
*
* Validate: int
*
* Required
*
2023-09-15 12:11:28 +02:00
* @var integer|null
*/
2023-09-15 12:11:28 +02:00
private ?int $operation = null;
/**
* The arcadia support code
*
* Validate: int
*
* Required
*
2023-09-15 12:11:28 +02:00
* @var integer|null
*/
2023-09-15 12:11:28 +02:00
private ?int $support_code = null;
/**
* The arcadia type support label
*
* Validate: string
*
* Required
*
2023-09-15 12:11:28 +02:00
* @var string|null
*/
2023-09-15 12:11:28 +02:00
private ?string $label_type_support = null;
/**
* The arcadia order date
*
* Validate: date
*
* Required
*
2023-09-15 12:11:28 +02:00
* @var string|null
*/
2023-09-15 12:11:28 +02:00
private ?string $order_date = null;
/**
* The arcadia code unique
*
* Validate: string
*
* Required
*
2023-09-15 12:11:28 +02:00
* @var string|null
*/
2023-09-15 12:11:28 +02:00
private ?string $code_unique = null;
/**
* The arcadia code on pack
*
* Validate: sometimes
*
* Required
*
2023-09-15 12:11:28 +02:00
* @var string|null
*/
2023-09-15 12:11:28 +02:00
private ?string $code_on_pack = null;
/**
* The crm customer fields
*
* @var array
*/
2023-10-05 12:16:43 +02:00
protected array $modelFields = [
2023-09-05 16:40:45 +02:00
'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
*/
2023-10-05 12:16:43 +02:00
protected static array $validation = [
2023-09-05 16:40:45 +02:00
'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',
2023-09-05 16:40:45 +02:00
'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.
*/
2023-09-05 16:40:45 +02:00
public function __set(string $field, mixed $value): void
{
if ($field === 'state_order') {
$value = (\is_object($value) and
2023-09-15 12:11:28 +02:00
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
2021-11-30 16:10:00 +01:00
get_class($properties['state_order']) === ArcadiaOrderType::class) ?
2025-08-28 16:41:48 +02:00
$properties['state_order']->value : (ctype_digit((string) $properties['state_order']) ?
(int) $properties['state_order'] : $properties['state_order']);
2023-10-05 12:16:43 +02:00
} catch (\TypeError | \BadMethodCallException) {
// * Cast anyway
2025-08-28 16:41:48 +02:00
$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();
2023-09-05 16:40:45 +02:00
$request = Utils::getResquest('apiV4.arcadia.outgoingMailGame', [], $this->jsonSerialize());
$response = static::$apiInterface->call($request);
2023-09-05 16:40:45 +02:00
if ($status = $response->status->equals(ApiStatus::OK)) {
$this->updatedValues = [];
}
$this->isNew = !$status;
return $status;
}
2021-08-16 13:22:34 +02:00
/**
* Serialize this object to an array
*
* @return array
*/
#[\ReturnTypeWillChange]
2021-08-16 13:22:34 +02:00
public function jsonSerialize()
{
return [
2023-09-05 16:40:45 +02:00
'deliver' => [
'email' => $this->email,
'firstname' => $this->firstname,
2023-09-05 16:40:45 +02:00
'lastname' => $this->lastname,
'phone' => $this->phone,
'address' => $this->address,
'address2' => $this->address2,
'city' => $this->city,
'postcode' => $this->postcode,
],
2023-09-05 16:40:45 +02:00
'operation' => $this->operation,
'support_code' => $this->support_code,
2021-08-16 13:22:34 +02:00
'label_type_support' => $this->label_type_support,
2023-09-05 16:40:45 +02:00
'order_date' => $this->order_date,
'code_unique' => $this->code_unique,
'code_on_pack' => $this->code_on_pack
2021-08-16 13:22:34 +02:00
];
}
}