<?php

namespace App\Classes\Modules\Affiliate\Services;

use App\Models\KeyValuePair;

class GetsAffiliateSettings
{
    const SETTING_KEY = 'affiliate_code_binding_days';
    const DEFAULT_VALUE = 30;

    /**
     * @return array
     */
    public function execute(): array
    {
        $keyValuePair = KeyValuePair::where('key', self::SETTING_KEY)
            ->whereNull('owner_type')
            ->whereNull('owner_id')
            ->first();

        $codeBindingDays = $keyValuePair ? (int) $keyValuePair->value : self::DEFAULT_VALUE;

        return [
            'code_binding_days' => $codeBindingDays
        ];
    }
}

