<?php

namespace App\Jobs\GrowingIO;

use App\Models\User\SignModel;
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 SignReportJob extends BaseReportJob implements ShouldQueue
{
    use Dispatchable;
    use InteractsWithQueue;
    use Queueable;
    use SerializesModels;

    /** @var SignModel */
    protected $sign;
    protected $platform;
    protected $user;

    public function __construct($sign, $platform)
    {
        $this->sign = $sign;
        $this->platform = $platform;
    }

    public function doHandle()
    {
        $this->user = UserModel::find($this->sign->uid);

        if (!$this->user) {
            return;
        }
        $this->doReport(self::SIGN, $this->sign->uid, [
            'type' => $this->getType(),
            'gender' => $this->getGender(),
        ]);
    }

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


    protected function getType()
    {
        switch ($this->platform) {
            case "wx":
                return "小程序签到";
            case "qq":
                return "小程序签到";
            case "ios":
                return "APP签到";
            case "android":
                return "APP签到";
        }
    }
}
