<?php

namespace App\Policies\Contact;

use App\Models\Contact\Hub\ContactMessage;
use App\Models\User\User;

class ContactMessagePolicy
{
    public function viewAny(User $user): bool
    {
        return $user->can('communications.logs.view.own')
            || $user->can('communications.logs.view.all');
    }

    public function view(User $user, ContactMessage $message): bool
    {
        if ($user->can('communications.logs.view.all')) {
            return true;
        }
        if ($user->can('communications.logs.view.own')) {
            return $message->created_by === $user->id
                || $message->solicitor_id === ($user->solicitor_id ?? null);
        }
        return false;
    }

    public function sendEmail(User $user): bool
    {
        return $user->can('communications.send.email');
    }

    public function sendSms(User $user): bool
    {
        return $user->can('communications.send.sms');
    }

    public function forceSend(User $user): bool
    {
        return $user->can('communications.send.force');
    }
}
