package com.example.sdksamples;

import com.impinj.octane.ImpinjReader;
import com.impinj.octane.Tag;
import com.impinj.octane.TagReport;
import com.impinj.octane.TagReportListener;

import java.util.List;

public class TagReportListenerImplementation implements TagReportListener {

    @Override
    public void onTagReported(ImpinjReader reader, TagReport report) {
        List<Tag> tags = report.getTags();

        for (Tag t : tags) {
            String tagOutput = " EPC: " + t.getEpc().toString();

            if ((reader.getName() != null) && !reader.getName().isEmpty()) {
                tagOutput += " Reader_name: " + reader.getName();
            } else {
                tagOutput += " Reader_ip: " + reader.getAddress();
            }

            if (t.isAntennaPortNumberPresent()) {
                tagOutput += " antenna: " + t.getAntennaPortNumber();
            }

            if (t.isFirstSeenTimePresent()) {
                tagOutput += " first: " + t.getFirstSeenTime().ToString();
            }

            if (t.isLastSeenTimePresent()) {
                tagOutput += " last: " + t.getLastSeenTime().ToString();
            }

            if (t.isSeenCountPresent()) {
                tagOutput += " count: " + t.getTagSeenCount();
            }

            if (t.isRfDopplerFrequencyPresent()) {
                tagOutput += " doppler: " + t.getRfDopplerFrequency();
            }

            if (t.isPeakRssiInDbmPresent()) {
                tagOutput += " peak_rssi: " + t.getPeakRssiInDbm();
            }

            if (t.isChannelInMhzPresent()) {
                tagOutput += " chan_MHz: " + t.getChannelInMhz();
            }

            if (t.isRfPhaseAnglePresent()) {
                tagOutput += " phase angle: " + t.getPhaseAngleInRadians();
            }

            if (t.isFastIdPresent()) {
                tagOutput += "\n     fast_id: " + t.getTid().toString();

                tagOutput += " model: " + t.getModelDetails().getModelName();

                tagOutput += " epcsize: " + t.getModelDetails().getEpcSizeBits();

                tagOutput += " usermemsize: " + t.getModelDetails().getUserMemorySizeBits();

                tagOutput += " Supports QT: " + t.getModelDetails().isSupportsQt();
            }

            if (t.isTxPowerPresent()) {
                tagOutput += " Transmit Power: " + t.getTxPower();
            }

            if (t.isXpcWordsPresent()) {
                tagOutput += "\n XPC Words: " + t.getXpc().toString();

                tagOutput += " XPC Words count: " + (t.getXpc().getCountBytes() / 2);
            }

            System.out.println(tagOutput);
        }
    }
}
