/*
  Copyright 2025 Matthias-Sebastian Schröder <matthias.schroeder@dolanghub.de>

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
*/

#pragma once

#include "dobase/screen.hpp"
#include <cstdint>

__NAMESPACE_DO_START

struct document_location_st
{
  uint32_t first_offset;
  uint32_t first_byte_offset;
  uint32_t first_line;
  uint32_t first_column;
  uint32_t last_offset;
  uint32_t last_byte_offset;
  uint32_t last_line;
  uint32_t last_column;
};

const document_location_st no_document_location = {};
const document_location_st unknown_document_location = {1, 1, 1, 1, 1, 1, 1, 1};

enum FoxProSyntaxinfotypes : uint32_t
{
  SYMBOL = 0,
  KEYWORD = 1,
  OPERATOR = 2,
  LITERAL = 3,
  COMMENT = 4,
  FUNCTION = 5,
  SUBSTITUTION = 6,
  INERT = 7,
};

struct syntax_info_st
{
  uint32_t type;
  document_location_st location;
};

struct call_info_st
{
  char* documentation = nullptr;
  document_location_st location;
};

struct error_location_st
{
  document_location_st location;
  document_location_st line;
};

class Charset;
class String;
class Variant;
class Runtime;
class VmStack;
class Class;
class Object;

// Alloc and free DO runtime handle
DOBASE_EXPORT Runtime* CreateRuntime(Screen *screen);

DOBASE_EXPORT void ReleaseRuntime(Runtime*);

// Run Shell or Program
DOBASE_EXPORT int RunDosh(Runtime* runtime);

// Run single command
DOBASE_EXPORT void RunCommand(Runtime* runtime, const String& command);

// Run multiple commands
DOBASE_EXPORT void RunScript(Runtime* runtime, const String& script);

// Run multiple commands
DOBASE_EXPORT void RunProgram(Runtime* runtime, const String& filename);

// Public syntax classifier-API for syntax highlighting
DOBASE_EXPORT int SyntaxClassifyString(Runtime* runtime, const char* data, size_t len, const Charset *cs,
  std::intptr_t* out_result_handle,
  std::uint32_t* out_num_syntaxinfo, std::uint32_t* out_num_macros,
    std::uint32_t* out_num_errors);

DOBASE_EXPORT int SyntaxFetchClassifications(std::intptr_t result_handle,
  syntax_info_st* out_syntax_info, document_location_st* out_macros,
    error_location_st* out_errors);

// Collect and out system information for debugging
DOBASE_EXPORT int CollectPrintSysinfo(Runtime* runtime);

// SET ASSERTS ON/OFF before running any user defined code
DOBASE_EXPORT void SetRuntimeAsserts(Runtime* runtime, bool val);

// Find a object factory
DOBASE_EXPORT Class* GetClass(VmStack* stack, const String* className);

DOBASE_EXPORT int GetMainStack(Runtime* runtime, VmStack **out_stack);

DOBASE_EXPORT bool FindFile(Runtime* runtime, const String&filename, String &found,
  bool ci_stem, bool ci_ext);

__NAMESPACE_END
