<?php

namespace App\Jobs\GrowingIO;

use App\Models\FlowerLogModel;
use App\Models\User\UserModel;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;

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

    /** @var FlowerLogModel */
    protected $flowerLog;
    /** @var UserModel */
    protected $user;

    public function __construct($flowerLog, $user)
    {
        $this->flowerLog = $flowerLog;
        $this->user = $user;
    }

    public function doHandle()
    {
        if (!$this->user) {
            return;
        }
        $this->doReport(self::SIGN_FLOWER, $this->flowerLog->uid, [
            'gender' => $this->getGender(),
            'type' => $this->flowerLog->remark,
            'amount_float' => $this->flowerLog->red_flower,
        ]);
    }

    protected function getGender()
    {
        switch ($this->user->gender) {
            case 1:
                return '男性';
            case 2:
                return '女性';
            default:
                return '未知';
        }
    }
}
