<?php

namespace App\Events;

use App\Exceptions\AlertException;
use App\Models\Media\MediaSecureImage;
use App\Models\Media\MediaSecureText;
use App\Models\Media\MediaSecureVoice;
use App\Models\Model;

/**
 * 提交审核素材事件
 * Class AuditMedia
 * @package App\Events
 */
class AuditMedia
{
    public $uid;
    public $type;
    public $origin;
    /**
     * @var model
     */
    public $storage;
    public $field;
    public $field_primary;
    public $failCallback;
    public $succCallback;


    /**
     * Create a new event instance.
     *
     * @param  int  $uid
     * @param  string  $type
     * @param  string  $origin
     * @param  string  $field
     * @param  null  $field_primary
     * @param  \Closure|string  $failCallback
     * @param  \Closure|string  $succCallback
     * @throws AlertException
     */
    public function __construct(
        int $uid,
        string $type,
        string $origin,
        string $field,
        $field_primary = null,
        $failCallback = null,
        $succCallback = null
    ) {
        $this->uid = $uid;
        $this->type = $type;
        $this->origin = $origin;
        $this->field = $field;
        $this->field_primary = $field_primary;
        $this->failCallback = $failCallback;
        $this->succCallback = $succCallback;
        $this->validateType();
    }


    public function validateType()
    {
        switch ($this->type) {
            case "text":
                $this->storage = new MediaSecureText();
                break;
            case "image":
                $this->storage = new MediaSecureImage();
                break;
            case "voice":
                $this->storage = new MediaSecureVoice();
                break;
        }
    }
}
