<?php

declare(strict_types=1);

namespace App\Policies;

use App\Models\Offer;
use App\Models\User;

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

    public function view(User $user, Offer $offer): bool
    {
        return $user->hasRole('admin')
            || $user->id === $offer->user_id
            || $user->id === $offer->created_by
            || $user->id === $offer->offer_to;
    }

    public function create(User $user): bool
    {
        return true;
    }

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

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

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

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