<?php

declare(strict_types=1);

namespace App\Policies;

use App\Models\Service;
use App\Models\User;

class ServicePolicy
{
    public function viewAny(?User $user): bool
    {
        return true;
    }

    public function view(?User $user, Service $service): bool
    {
        if ($service->status === 'active' && $service->is_active) {
            return true;
        }

        return $user !== null && ($user->hasRole('admin') || $user->id === $service->created_by);
    }

    public function create(User $user): bool
    {
        return $user->hasRole('admin');
    }

    public function update(User $user, Service $service): bool
    {
        return $user->id === $service->created_by || $user->hasRole('admin');
    }

    public function delete(User $user, Service $service): bool
    {
        return $user->id === $service->created_by || $user->hasRole('admin');
    }

    public function restore(User $user, Service $service): bool
    {
        return $user->hasRole('admin');
    }

    public function forceDelete(User $user, Service $service): bool
    {
        return $user->hasRole('admin');
    }
}
