<?php

namespace App\Jobs\GrowingIO;

use App\Generated\BOs\Enums\FriendInvitationType;
use App\Models\Deed\InvitationCardModel;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;

class FriendInvitationReportJob extends BaseReportJob implements ShouldQueue
{
    use Dispatchable;
    use InteractsWithQueue;
    use Queueable;
    use SerializesModels;

    /** @var InvitationCardModel */
    protected $invitationCard;
    protected $questions;

    public function __construct($invitationCard, $questions)
    {
        $this->invitationCard = $invitationCard;
        $this->questions = $questions;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function doHandle()
    {
        try {
            $types = array_column($this->questions, 'type');

            $this->doReport(self::FRIEND_INVITATION, $this->invitationCard->uid, [
                'related_id' => $this->invitationCard->invite_uid,
                'has_asking' => in_array(FriendInvitationType::ASKING, $types) ? '是' : '否',
                'has_singing' => in_array(FriendInvitationType::SINGING, $types) ? '是' : '否',
                'has_drawing' => in_array(FriendInvitationType::DRAWING, $types) ? '是' : '否',
            ]);
        } catch (\Throwable $exception) {
            \Log::error($exception);
        }
    }
}
