content: /*
   ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
   ~                                                                               ~
   ~ The MIT License (MIT)                                                         ~
   ~                                                                               ~
   ~ Copyright (c) 2015-2025 miaixz.org OSHI and other contributors.               ~
   ~                                                                               ~
   ~ Permission is hereby granted, free of charge, to any person obtaining a copy  ~
   ~ of this software and associated documentation files (the "Software"), to deal ~
   ~ in the Software without restriction, including without limitation the rights  ~
   ~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell     ~
   ~ copies of the Software, and to permit persons to whom the Software is         ~
   ~ furnished to do so, subject to the following conditions:                      ~
   ~                                                                               ~
   ~ The above copyright notice and this permission notice shall be included in    ~
   ~ all copies or substantial portions of the Software.                           ~
   ~                                                                               ~
   ~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR    ~
   ~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,      ~
   ~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE   ~
   ~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER        ~
   ~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, ~
   ~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN     ~
   ~ THE SOFTWARE.                                                                 ~
   ~                                                                               ~
   ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
  */
  package org.miaixz.bus.health.unix.platform.freebsd.hardware;
  
  import java.util.function.Supplier;
  
  import org.miaixz.bus.core.lang.Normal;
  import org.miaixz.bus.core.lang.annotation.Immutable;
  import org.miaixz.bus.core.lang.tuple.Triplet;
  import org.miaixz.bus.core.xyz.StringKit;
  import org.miaixz.bus.health.Executor;
  import org.miaixz.bus.health.Memoizer;
  import org.miaixz.bus.health.Parsing;
  import org.miaixz.bus.health.builtin.hardware.common.AbstractFirmware;
  
  /**
   * Firmware information from dmidecode
   *
   * @author Kimi Liu
   * @since Java 17+
   */
  @Immutable
  final class FreeBsdFirmware extends AbstractFirmware {
  
      private final Supplier<Triplet<String, String, String>> manufVersRelease = Memoizer
              .memoize(FreeBsdFirmware::readDmiDecode);
  
      private static Triplet<String, String, String> readDmiDecode() {
          String manufacturer = null;
          String version = null;
          String releaseDate = Normal.EMPTY;
  
          // $ sudo dmidecode -t bios
          // # dmidecode 3.0
          // Scanning /dev/mem for entry point.
          // SMBIOS 2.7 present.
          //
          // Handle 0x0000, DMI type 0, 24 bytes
          // BIOS Information
          // Vendor: Parallels Software International Inc.
          // Version: 11.2.1 (32626)
          // Release Date: 07/15/2016
          // ... <snip> ...
          // BIOS Revision: 11.2
          // Firmware Revision: 11.2
  
          final String manufacturerMarker = "Vendor:";
          final String versionMarker = "Version:";
          final String releaseDateMarker = "Release Date:";
  
          // Only works with root permissions but it's all we've got
          for (final String checkLine : Executor.runNative("dmidecode -t bios")) {
              if (checkLine.contains(manufacturerMarker)) {
                  manufacturer = checkLine.split(manufacturerMarker)[1].trim();
              } else if (checkLine.contains(versionMarker)) {
                  version = checkLine.split(versionMarker)[1].trim();
              } else if (checkLine.contains(releaseDateMarker)) {
                  releaseDate = checkLine.split(releaseDateMarker)[1].trim();
              }
          }
          releaseDate = Parsing.parseMmDdYyyyToYyyyMmDD(releaseDate);
          return Triplet.of(
                  StringKit.isBlank(manufacturer) ? Normal.UNKNOWN : manufacturer,
                  StringKit.isBlank(version) ? Normal.UNKNOWN : version,
                  StringKit.isBlank(releaseDate) ? Normal.UNKNOWN : releaseDate);
      }
  
      @Override
      public String getManufacturer() {
          return manufVersRelease.get().getLeft();
      }
  
      @Override
      public String getVersion() {
          return manufVersRelease.get().getMiddle();
      }
  
      @Override
      public String getReleaseDate() {
          return manufVersRelease.get().getRight();
      }
  
  }
  