/*
  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/namespace.hpp"
#include <cstddef>

__NAMESPACE_DO_START

// Codepages only supported by DO
#define DOCP_WIN_65001      65001

// Codepages supported by FoxPro
#define DOCP_IBM_437          437
#define DOCP_IBM_737          737
#define DOCP_FOX_620          620
#define DOCP_IBM_850          850
#define DOCP_IBM_852          852
#define DOCP_IBM_857          857
#define DOCP_IBM_861          861
#define DOCP_IBM_865          865
#define DOCP_IBM_866          866
#define DOCP_WIN_874          874
#define DOCP_FOX_895          895
#define DOCP_WIN_932          932
#define DOCP_WIN_936          936
#define DOCP_WIN_949          949
#define DOCP_WIN_950          950
#define DOCP_WIN_1250        1250
#define DOCP_WIN_1251        1251
#define DOCP_WIN_1252        1252
#define DOCP_WIN_1253        1253
#define DOCP_WIN_1254        1254
#define DOCP_WIN_1255        1255
#define DOCP_WIN_1256        1256
#define DOCP_MAC_10000      10000
#define DOCP_MAC_10006      10006
#define DOCP_MAC_10007      10007
#define DOCP_MAC_10029      10029

constexpr int DOCS_MASK_CS = 0x0000FFFF;
constexpr int DOCS_MASK_NOCPTRANS = 0x00010000;

// Charsets supported by DO
#define DOCS_ASCII          1
#define DOCS_BINARY         2
#define DOCS_GSM            3
#define DOCS_ISO_8859_1     4
#define DOCS_ISO_8859_2     5
#define DOCS_ISO_8859_3     6
#define DOCS_ISO_8859_4     7
#define DOCS_ISO_8859_5     8
#define DOCS_ISO_8859_6     9
#define DOCS_ISO_8859_7    10
#define DOCS_ISO_8859_8    11
#define DOCS_ISO_8859_9    12
#define DOCS_ISO_8859_10   13
#define DOCS_ISO_8859_11   14
#define DOCS_ISO_8859_13   15
#define DOCS_ISO_8859_14   16
#define DOCS_ISO_8859_15   17
#define DOCS_IBM_37        18
#define DOCS_IBM_437       19
#define DOCS_IBM_737       20
#define DOCS_IBM_500       21
#define DOCS_IBM_850       22
#define DOCS_IBM_852       23
#define DOCS_IBM_857       24
#define DOCS_IBM_861       25
#define DOCS_IBM_863       26
#define DOCS_IBM_865       27
#define DOCS_IBM_866       28
#define DOCS_IBM_950       29
#define DOCS_IBM_1373      30
#define DOCS_IBM_1375      31
#define DOCS_IBM_5471      32
#define DOCS_KAMENICKY     33
#define DOCS_MAZOVIA       34
#define DOCS_UTF_7         35
#define DOCS_UTF_8         36
#define DOCS_UTF_16LE      37
#define DOCS_UTF_16BE      38
#define DOCS_UTF_32LE      39
#define DOCS_UTF_32BE      40
#define DOCS_WIN_874       41
#define DOCS_WIN_932       42
#define DOCS_WIN_936       43
#define DOCS_WIN_949       44
#define DOCS_WIN_950       45
#define DOCS_WIN_1250      46
#define DOCS_WIN_1251      47
#define DOCS_WIN_1252      48
#define DOCS_WIN_1253      49
#define DOCS_WIN_1254      50
#define DOCS_WIN_1255      51
#define DOCS_WIN_1256      52
#define DOCS_WIN_1257      53
#define DOCS_WIN_1258      54
#define DOCS_MAC           55
#define DOCS_MAC_GREEK     56
#define DOCS_MAC_CYRILLIC  57
#define DOCS_MAC_EE        58
#define DOCS_UTF_8_BOM     59
#define DOCS_UTF_16LE_BOM  60
#define DOCS_UTF_16BE_BOM  61
#define DOCS_UTF_32LE_BOM  62
#define DOCS_UTF_32BE_BOM  63

class Charset;

enum class CstranRecovery
{
  // Replace char with supplemental character
  // for example, a question mark ?
  SUBSTITUTE,
  // Abort conversion if encountering a char
  // that cannot be converted to target charset
  ABORT
};

// Lookup charset by DO-Charset-Identifyer
DOBASE_EXPORT const Charset* GetCharsetByCSID(size_t csid);

// Lookup charset by windows codepage which can be
// found by calling GetACP-Function on Windows
DOBASE_EXPORT const Charset* GetCharsetByWindowsCodepage(int cp);

DOBASE_EXPORT size_t GetCharsetCSID(const Charset* cs);

DOBASE_EXPORT size_t GetCharsetCPID(const Charset* cs);

__NAMESPACE_END
