using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Assets.Scripts.Devices.Ant.Pages
{
    public class ManufacturerDataPageHandler : IPageHandler
    {
        private readonly Action<ManufacturerDataPageContent> _callback;
        public ManufacturerDataPageHandler(Action<ManufacturerDataPageContent> callback)
        {
            _callback = callback;
        }


        public bool CanHandle(byte pageNumber)
        {
            return pageNumber == 80;
        }

        public void Handle(byte[] dataPayload, AbstractAntDevice device)
        {
            int hwRevision = dataPayload[3];
            int mfgId = (int)dataPayload[4] | (int)dataPayload[5] << 8;
            int modelNumber = (int)((int)dataPayload[6] | (int)dataPayload[7] << 8);

            //device.ManufacturerId = mfgId;
            _callback(new ManufacturerDataPageContent(hwRevision, mfgId, modelNumber));
        }
    }
}
