export class ZktecoGateway {
  constructor({ registry, logger }) {
    this.registry = registry;
    this.logger = logger;
  }

  async pullLogs(serialNo) {
    const device = await this.registry.find(serialNo);
    this.logger.info({ serialNo }, 'pulling attendance logs');

    return {
      device,
      synced: 0,
      logs: [],
      message: 'Gateway contract ready. Add vendor SDK/TCP protocol implementation here.',
    };
  }

  async pushUser(serialNo, employee) {
    const device = await this.registry.find(serialNo);
    this.logger.info({ serialNo, employeeCode: employee.employeeCode }, 'pushing user to device');

    return {
      deviceSerialNo: device.serialNo,
      employeeCode: employee.employeeCode,
      status: 'queued',
    };
  }

  async restart(serialNo) {
    const device = await this.registry.find(serialNo);
    this.logger.warn({ serialNo }, 'remote restart requested');

    return {
      deviceSerialNo: device.serialNo,
      status: 'queued',
    };
  }

  async receivePushLog(serialNo, payload) {
    const device = await this.registry.find(serialNo);

    return {
      tenantId: device.tenantId,
      deviceSerialNo: serialNo,
      accepted: true,
      logsReceived: Array.isArray(payload.logs) ? payload.logs.length : 1,
    };
  }
}
