<?php

namespace App\Http\Controllers\Affiliate;

use App\Classes\Modules\Affiliate\ControllersLogic\DeleteAffiliateLogic;
use App\Models\Affiliate;
use Illuminate\Http\JsonResponse;

class DeleteAffiliateController
{
    /**
     * @param int $id
     * @param DeleteAffiliateLogic $logic
     * @return JsonResponse
     * @throws \Illuminate\Auth\Access\AuthorizationException
     */
    public function delete(int $id, DeleteAffiliateLogic $logic): JsonResponse {
        $affiliate = Affiliate::findOrFail($id);
        $this->authorize('delete', $affiliate);
        return $logic->execute($id);
    }
    
    /**
     * Authorize a given action for the current user.
     *
     * @param  mixed  $ability
     * @param  mixed|array  $arguments
     * @return \Illuminate\Auth\Access\Response
     *
     * @throws \Illuminate\Auth\Access\AuthorizationException
     */
    public function authorize($ability, $arguments = [])
    {
        return app(\Illuminate\Contracts\Auth\Access\Gate::class)->authorize($ability, $arguments);
    }
}

