#pragma once
#include <Arduino.h>
#include <MFRC522.h>
#include <rdm6300.h>
#include <Adafruit_PN532.h>

class Reader {
public:
	virtual bool canHaveUnstableIdentifier() = 0;
	virtual bool isNewCardPresent() = 0;
	virtual String getReaderName() = 0;
	virtual String getCardUid() = 0;
	virtual void begin() = 0;
	virtual void reset() = 0;
	virtual void init() = 0;
	virtual void end() = 0;
};

class MFRC522Reader : public Reader {
private:
	MFRC522* mfrc522;
public:
	explicit MFRC522Reader(byte chipSelectPin, byte resetPowerDownPin);
	bool canHaveUnstableIdentifier() override;
	bool isNewCardPresent() override;
	String getReaderName() override;
	String getCardUid() override;
	void begin() override;
	void reset() override;
	void init() override;
	void end() override;
};

class RDM6300Reader : public Reader {
private:
	Rdm6300* rdm6300;
	int pin;
public:
	explicit RDM6300Reader(int pin);
	bool canHaveUnstableIdentifier() override;
	bool isNewCardPresent() override;
	String getReaderName() override;
	String getCardUid() override;
	void begin() override;
	void reset() override;
	void init() override;
	void end() override;
};

class PN532Reader : public Reader {
private:
	Adafruit_PN532* pn532;
	uint8_t uid[16];
	uint8_t uidLength;
	unsigned long timer = 0;
public:
	static volatile int irq;
	static volatile bool toggleMode;
	static uint8_t mode;
	explicit PN532Reader(uint8_t ss);
	bool canHaveUnstableIdentifier() override;
	bool isNewCardPresent() override;
	String getReaderName() override;
	String getCardUid() override;
	void cycleMode();
	void beginKeepMode();
	void begin() override;
	void reset() override;
	void init() override;
	void end() override;
};
