<commit_before><?php namespace PCI\Listeners\Email;

use Date;
use Illuminate\Mail\Message;
use PCI\Events\NewPetitionCreation;
use PCI\Models\Attendant;
use PCI\Models\Depot;

/**
 * Class EmailPetitionEventToAttendants
 *
 * @package PCI\Listeners
 * @author  <NAME> <<EMAIL>>
 * @link    https://github.com/slayerfat/sistemaPCI Repositorio en linea.
 */
class EmailPetitionEventToAttendants extends AbstractEmailListener
{

    /**
     * Handle the event.
     *
     * @param  NewPetitionCreation $event
     * @return void
     */
    public function handle(NewPetitionCreation $event)
    {
        $petition             = $event->petition;
        $user                 = $event->user;
        $date                 = Date::now();
        $emails['attendants'] = $this->getAttendantsEmail();
        $emails['owner']      = $this->getOwnerEmail();

        $this->mail->send(
            [
                'emails.petitions.created-attendants',
                'emails.petitions.created-attendants-plain',
            ],
            compact('user', 'petition'),
            function ($message) use ($emails, $user, $petition, $date) {
                /** @var Message $message */
                $message->to($emails['attendants'])
                    ->bcc($emails['owner'])
                    ->subject(
                        "sistemaPCI: Nuevo ."
                        . trans('models.petitions.singular')
                        . " #" . $petition->id
                        . " ha sido creado por " . $user->email
                        . " con fecha de " . $date . "."
                    );
            }
        );
    }

    /**
     * Busca los correos de los encargados de almacen en el sistema.
     *
     * @return array
     */
    private function getAttendantsEmail()
    {
        $emails = [];

        // TODO: repo
        Attendant::all()->load('users')
            ->each(function ($attendant) use (&$emails) {
                $emails[] = $attendant->user->email;
            });

        return $emails;
    }

    /**
     * Regresa el correo del jefe de almacen.
     *
     * @return string<commit_msg>:cry: encargados tienen un usuario<commit_after><?php namespace PCI\Listeners\Email;

use Date;
use Illuminate\Mail\Message;
use PCI\Events\NewPetitionCreation;
use PCI\Models\Attendant;
use PCI\Models\Depot;

/**
 * Class EmailPetitionEventToAttendants
 *
 * @package PCI\Listeners
 * @author  <NAME> <<EMAIL>>
 * @link    https://github.com/slayerfat/sistemaPCI Repositorio en linea.
 */
class EmailPetitionEventToAttendants extends AbstractEmailListener
{

    /**
     * Handle the event.
     *
     * @param  NewPetitionCreation $event
     * @return void
     */
    public function handle(NewPetitionCreation $event)
    {
        $petition             = $event->petition;
        $user                 = $event->user;
        $date                 = Date::now();
        $emails['attendants'] = $this->getAttendantsEmail();
        $emails['owner']      = $this->getOwnerEmail();

        $this->mail->send(
            [
                'emails.petitions.created-attendants',
                'emails.petitions.created-attendants-plain',
            ],
            compact('user', 'petition'),
            function ($message) use ($emails, $user, $petition, $date) {
                /** @var Message $message */
                $message->to($emails['attendants'])
                    ->bcc($emails['owner'])
                    ->subject(
                        "sistemaPCI: Nuevo ."
                        . trans('models.petitions.singular')
                        . " #" . $petition->id
                        . " ha sido creado por " . $user->email
                        . " con fecha de " . $date . "."
                    );
            }
        );
    }

    /**
     * Busca los correos de los encargados de almacen en el sistema.
     *
     * @return array
     */
    private function getAttendantsEmail()
    {
        $emails = [];

        // TODO: repo
        Attendant::all()->load('user')
            ->each(function ($attendant) use (&$emails) {
                $emails[] = $attendant->user->email;
            });

        return $emails;
    }

    /**
     * Regresa el correo del jefe de almacen.
     *
     * @return string
{'fraction_non_alphanumeric': 0.1341689879294336, 'fraction_numerical': 0.0, 'mean_word_length': 1.5542382928275045, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 39, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3747745', 'n_tokens_mistral': 1257, 'n_tokens_neox': 1184, 'n_words': 241}