<?php

namespace App\Classes\Modules\Affiliate\ControllersLogic;

use App\Classes\Modules\Affiliate\Services\DeletesAffiliate;
use App\Models\Affiliate;
use Illuminate\Http\JsonResponse;

class DeleteAffiliateLogic
{
    /** @var DeletesAffiliate */
    private $deletesAffiliate;

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

    /**
     * @param int $id
     * @return JsonResponse
     */
    public function execute(int $id): JsonResponse
    {
        $affiliate = Affiliate::findOrFail($id);
        $this->deletesAffiliate->execute($affiliate);

        return response()->json([
            'message' => 'Affiliate code deleted successfully'
        ]);
    }
}

