<?php
use Modules\Contracts\Models\ContractStatus;
use Modules\Contracts\Models\Contract;

if (!function_exists('GetContractStatuses'))
{
    function GetContractStatuses()
    {
        return [
            ContractStatus::NEW         => ContractStatus::getName(ContractStatus::NEW),
            ContractStatus::RESERVATION => ContractStatus::getName(ContractStatus::RESERVATION),
            ContractStatus::SUCCESS     => ContractStatus::getName(ContractStatus::SUCCESS),
            ContractStatus::DECLINE     => ContractStatus::getName(ContractStatus::DECLINE),
            ContractStatus::TREATY      => ContractStatus::getName(ContractStatus::TREATY),
        ];
    }
}

if (!function_exists('GetAgentPaymentForContract'))
{
    function GetAgentPaymentForContract(Contract $contract)
    {
        $agent = $contract->deal->agent;
        $agentPaymentable = $agent->getPaymentable($contract->deal->complex);
        $rewardPercent = $agentPaymentable->getPaymentablePercent();
        if (!$rewardPercent)
        {
            $rewardPercent = 0;
        }
        $price = $contract->price;
        return ($price * $rewardPercent) / 100;
    }
}