// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// This file was automatically generated from {{ template_file }}.
// See {{ readme_file }} for details about how to make changes.

#include "components/error_page/common/alt_game_images.h"

#include <memory>
#include <string>

#include "base/base64url.h"
#include "base/logging.h"
#include "base/rand_util.h"
#include "base/strings/string_util.h"

namespace error_page {
namespace {
{% for image in images_1x %}
  const uint8_t kAltGameImages1x{{ image.name }}[] = {
    {{ image.literals }}
  };
{% endfor %}

const uint8_t* const kAltGameImages1x[] = {
  {% for image in images_1x %}
    kAltGameImages1x{{ image.name }},
  {% endfor %}
};
constexpr int kAltGameImagesCount = std::size(kAltGameImages1x);
const size_t kAltGameImages1xLength[] = {
  {% for image in images_1x %}
    std::size(kAltGameImages1x{{ image.name }}),
  {% endfor %}
};
static_assert(std::size(kAltGameImages1xLength) == kAltGameImagesCount, "");

{% for image in images_2x %}
  const uint8_t kAltGameImages2x{{ image.name }}[] = {
    {{ image.literals }}
  };
{% endfor %}

const uint8_t* const kAltGameImages2x[] = {
  {% for image in images_2x %}
    kAltGameImages2x{{ image.name }},
  {% endfor %}
};

const size_t kAltGameImages2xLength[] = {
  {% for image in images_2x %}
    std::size(kAltGameImages2x{{ image.name }}),
  {% endfor %}
};

static_assert(std::size(kAltGameImages2x) == kAltGameImagesCount, "");
static_assert(std::size(kAltGameImages2xLength) == kAltGameImagesCount, "");

}  // namespace

static_assert(kAltGameImagesCount > 1, "");

size_t CountAlternateImages() {
  return kAltGameImagesCount;
}

bool LookupObfuscatedImage(int id, int scale, std::string* image) {
  if (id < 0 || id >= kAltGameImagesCount)
    return false;

  if (scale == 1) {
    *image = std::string(reinterpret_cast<const char*>(kAltGameImages1x[id]),
                         kAltGameImages1xLength[id]);
    return true;
  }
  if (scale == 2) {
    *image = std::string(reinterpret_cast<const char*>(kAltGameImages2x[id]),
                         kAltGameImages2xLength[id]);
    return true;
  }
  return false;
}

}  // namespace error_page
