<?php

namespace LaraBB\Peer\Tasks;

use LaraBB\Peer\Models\Peer;

class UpdateTask
{
    /**
     * @param Peer $peer
     * @param array $data
     * @return bool
     */
    public function run(Peer $peer, array $data): bool
    {
        $peer->updated_uuid = $data['updated_uuid'] ?? $peer->updated_uuid;
        $peer->torrent_uuid = $data['torrent_uuid'] ?? $peer->torrent_uuid;
        $peer->peer_id      = $data['peer_id'] ?? $peer->peer_id;
        $peer->ip           = $data['ip'] ?? $peer->ip;
        $peer->port         = $data['port'] ?? $peer->port;
        $peer->status       = $data['status'] ?? $peer->status;
        $peer->natuser      = $data['natuser'] ?? $peer->natuser;
        $peer->client       = $data['client'] ?? $peer->client;
        $peer->dns          = $data['dns'] ?? $peer->dns;
        $peer->uploaded     = $data['uploaded'] ?? $peer->uploaded;
        $peer->downloaded   = $data['downloaded'] ?? $peer->downloaded;

        return $peer->save();
    }
}
