// MIT License
// Copyright (c) 2026 by Peter Siegmund (mars3142)
// 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.

#pragma once

#include "cartridge/binary_reader.h"
#include "cartridge/lat_lng.h"
#include "cartridge/media.h"
#include <map>
#include <memory>
#include <string>
#include <vector>

namespace cartridge {

class Cartridge {
public:
  // Factory method to create Cartridge from BinaryReader
  static std::unique_ptr<Cartridge> create(BinaryReader &reader);

  // Getters
  [[nodiscard]] double altitude() const;
  [[nodiscard]] const std::string &author() const;
  [[nodiscard]] const LatLng &latLng() const;
  [[nodiscard]] const std::string &cartridgeName() const;
  [[nodiscard]] const std::string &cartridgeDesc() const;
  [[nodiscard]] const std::string &cartridgeGuid() const;
  [[nodiscard]] const std::string &typeOfCartridge() const;
  [[nodiscard]] const std::string &playerName() const;
  [[nodiscard]] const std::string &startLocationDesc() const;
  [[nodiscard]] const std::string &version() const;
  [[nodiscard]] const std::string &company() const;
  [[nodiscard]] const std::string &recommendDevice() const;
  [[nodiscard]] const std::string &completionCode() const;

  // Media methods
  std::unique_ptr<Media> getMedia(int objectId);
  [[nodiscard]] int mediaCount() const;
  std::unique_ptr<Media> splashScreen();
  std::unique_ptr<Media> smallIcon();
  std::unique_ptr<Media> luac();

  // Comparison operators
  bool operator==(const Cartridge &other) const;
  bool operator!=(const Cartridge &other) const;

  Cartridge(std::string cartridgeGuid, double altitude, std::string author,
            std::string cartridgeDesc, std::string cartridgeName,
            std::string company, std::string completionCode, LatLng latLng,
            std::string playerName, std::string recommendDevice,
            int smallIconId, int splashScreenId, std::string startLocationDesc,
            std::string typeOfCartridge, std::string version,
            std::map<int, int> references, std::vector<uint8_t> bytes);

private:
  // Fields
  std::string m_cartridgeGuid;
  double m_altitude;
  std::string m_author;
  std::string m_cartridgeDesc;
  std::string m_cartridgeName;
  std::string m_company;
  std::string m_completionCode;
  LatLng m_latLng;
  std::string m_playerName;
  std::string m_recommendDevice;
  int m_smallIconId;
  int m_splashScreenId;
  std::string m_startLocationDesc;
  std::string m_typeOfCartridge;
  std::string m_version;
  std::map<int, int> m_references;
  std::vector<uint8_t> m_bytes;

  int m_lastObject = -1;
  std::unique_ptr<Media> m_lastMedia;
};

} // namespace cartridge
