<?php

namespace App\Classes\Modules\Affiliate\ControllersLogic;

use App\Classes\Modules\Affiliate\Services\UpdatesAffiliateSettings;
use App\Classes\Modules\Affiliate\DataTransferObjects\AffiliateSettingsObject;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class UpdateAffiliateSettingsLogic
{
    /** @var UpdatesAffiliateSettings */
    private $updatesAffiliateSettings;

    /**
     * @param UpdatesAffiliateSettings $updatesAffiliateSettings
     */
    public function __construct(UpdatesAffiliateSettings $updatesAffiliateSettings)
    {
        $this->updatesAffiliateSettings = $updatesAffiliateSettings;
    }

    /**
     * @param Request $request
     * @return JsonResponse
     */
    public function execute(Request $request): JsonResponse
    {
        $object = new AffiliateSettingsObject(
            $request->input('code_binding_days', 30)
        );

        $settings = $this->updatesAffiliateSettings->execute($object);
        
        return response()->json([
            'message' => 'Affiliate settings updated successfully',
            'data' => $settings
        ]);
    }
}

