<?php

namespace LaraBB\Torrent\Tasks;

use LaraBB\Torrent\Models\Torrent;

/**
 *
 */
class StoreTask
{
    /**
     * @param Torrent $torrent
     */
    public function __construct(
        private readonly Torrent $torrent
    ) {

    }

    /**
     * @param array $data
     * @return Torrent
     */
    public function run(array $data): Torrent
    {
        $this->torrent->created_uuid = $data['created_uuid'];
        $this->torrent->updated_uuid = $data['updated_uuid'];
        $this->torrent->infohash     = $data['infohash'];
        $this->torrent->filename     = $data['filename'];
        $this->torrent->name         = $data['name'];
        $this->torrent->size         = $data['size'];

        $this->torrent->save();

        return $this->torrent;
    }
}
