<?php
namespace Whater\Domain\Product\Model;
use Whater\Domain\Common\Exception\InvalidUUIDException;
use Ramsey\Uuid\Uuid;
use Whater\Domain\Product\Exception\InvalidWalletLiquidationRequestCurrencyException;
use Whater\Domain\Product\Exception\InvalidWalletLiquidationRequestMoneyException;
use Whater\Domain\Product\Exception\InvalidWalletLiquidationRequestStatusException;
use Whater\Domain\Product\Exception\InvalidWalletLiquidationRequestTypeException;
use Whater\Domain\Whater\Model\WhaterOrganization;
/**
*
* @package Whater\Domain\Product\Model
*/
class WalletLiquidationRequest
{
const WLR_TYPE_REQUEST_BY_ORGANIZATION = 'WLR_TYPE_REQUEST_BY_ORGANIZATION';
const WLR_TYPE_REQUEST_BY_ADMIN = 'WLR_TYPE_REQUEST_BY_ADMIN';
const WLR_TYPE_REQUEST_AUTOMATICALLY = 'WLR_TYPE_REQUEST_AUTOMATICALLY';
const WLR_STATUS_PENDING = 'WLR_STATUS_PENDING';
const WLR_STATUS_CONFIRMED = 'WLR_STATUS_CONFIRMED';
const WLR_STATUS_CANCELED = 'WLR_STATUS_CANCELED';
/**
* @var string
*/
protected $uuid;
/**
* @var string
*/
protected $status;
/**
* @var string
*/
protected $requestType;
/**
* @var \DateTime
*/
protected $liquidationDate;
/**
* @var string
*/
private $bankAccountOwnerName;
/**
* @var string
*/
private $bankAccountIbanNumber;
/**
* @var string
*/
private $bankAccountBicSwiftNumber;
/**
* @var WhaterOrganization
*/
protected $whaterOrganization;
/**
* @var float
*/
protected $money;
/**
* @var float
*/
protected $coins;
/**
* @var string
*/
protected $currency;
/**
* @var string
*/
protected $privateNote;
/**
* @var string
*/
protected $publicNote;
/**
* @var \DateTime
*/
protected $createdAt;
/**
* @var WalletOperation
*/
protected $walletOperation;
/**
* WalletLiquidationRequest constructor.
*/
public function __construct(
string $walletLiquidationRequestId = null,
string $requestType,
WhaterOrganization $whaterOrganization,
float $money,
float $coins,
string $currency = WalletOperation::WO_CURRENCY_EURO
) {
try {
$this->uuid = Uuid::fromString($walletLiquidationRequestId ?: Uuid::uuid4())->toString();
} catch (\InvalidArgumentException $e) {
throw new InvalidUUIDException();
}
$this->whaterOrganization = $whaterOrganization;
if ($money < 0 || $coins < 0) {
throw new InvalidWalletLiquidationRequestMoneyException();
}
$this->money = $money;
$this->coins = $coins;
$this->status = WalletLiquidationRequest::WLR_STATUS_PENDING;
switch ($requestType) {
case WalletLiquidationRequest::WLR_TYPE_REQUEST_AUTOMATICALLY:
case WalletLiquidationRequest::WLR_TYPE_REQUEST_BY_ADMIN:
case WalletLiquidationRequest::WLR_TYPE_REQUEST_BY_ORGANIZATION:
$this->requestType = $requestType;
break;
default:
throw new InvalidWalletLiquidationRequestTypeException();
}
if ($currency = !null) {
switch ($currency) {
case WalletOperation::WO_CURRENCY_EURO:
$this->currency = $currency;
break;
default:
throw new InvalidWalletLiquidationRequestCurrencyException();
}
}
$this->createdAt = new \DateTime();
}
public function updateRequest(
string $bankAccountOwnerName = null,
string $bankAccountIbanNumber = null,
string $bankAccountBicSwiftNumber = null
) {
$this->bankAccountOwnerName = $bankAccountOwnerName;
$this->bankAccountIbanNumber = $bankAccountIbanNumber;
$this->bankAccountBicSwiftNumber = $bankAccountBicSwiftNumber;
return $this;
}
public function updateStatus(
string $status,
float $money,
float $coins,
\DateTime $liquidationDate = null,
WalletOperation $walletOperation = null
) {
if ($money < 0 || $coins < 0) {
throw new InvalidWalletLiquidationRequestMoneyException();
}
if ($this->status() != WalletLiquidationRequest::WLR_STATUS_CONFIRMED) {
$this->money = $money;
$this->coins = $coins;
}
$this->walletOperation = $walletOperation;
switch ($status) {
case WalletLiquidationRequest::WLR_STATUS_PENDING:
case WalletLiquidationRequest::WLR_STATUS_CANCELED:
$this->money = $money;
$this->coins = $coins;
$this->status = $status;
break;
case WalletLiquidationRequest::WLR_STATUS_CONFIRMED:
if ($this->liquidationDate == null) {
$this->liquidationDate = new \DateTime();
}
if ($this->walletOperation == null && $this->status == WalletLiquidationRequest::WLR_STATUS_CONFIRMED) {
throw new InvalidWalletLiquidationRequestStatusException();
}
$this->status = $status;
break;
default:
throw new InvalidWalletLiquidationRequestTypeException();
}
$this->liquidationDate = $liquidationDate;
return $this;
}
public function updateNotes(
string $privateNote = null,
string $publicNote = null
) {
$this->privateNote = $privateNote;
$this->publicNote = $publicNote;
return $this;
}
/**
* @return string
*/
public function id(): string
{
return $this->uuid;
}
/**
* @return WhaterOrganization
*/
public function whaterOrganization(): ?WhaterOrganization
{
return $this->whaterOrganization;
}
/**
* @return \DateTime
*/
public function liquidationDate(): ?\DateTime
{
return $this->liquidationDate;
}
/**
* @return string
*/
public function status(): string
{
return $this->status;
}
/**
* @return string
*/
public function requestType(): string
{
return $this->requestType;
}
/**
* @return float
*/
public function money(): float
{
return $this->money;
}
/**
* @return float
*/
public function coins(): float
{
return $this->coins;
}
/**
* @return string
*/
public function currency(): string
{
return $this->currency;
}
/**
* @return string
*/
public function bankAccountOwnerName()
{
return $this->bankAccountOwnerName;
}
/**
* @return string
*/
public function bankAccountIbanNumber()
{
return $this->bankAccountIbanNumber;
}
/**
* @return string
*/
public function bankAccountBicSwiftNumber()
{
return $this->bankAccountBicSwiftNumber;
}
/**
* @return string
*/
public function privateNote(): ?string
{
return $this->privateNote;
}
/**
* @return string
*/
public function publicNote(): ?string
{
return $this->publicNote;
}
/**
* @return WalletOperation
*/
public function walletOperation(): ?WalletOperation
{
return $this->walletOperation;
}
/**
* @return \DateTime
*/
public function createdAt(): \DateTime
{
return $this->createdAt;
}
}