/*
     Description: 碱基相关的工具函数

     Copyright : All right reserved by ICT

     Author : Zhang Zhonghai
     Date : 2025/12/29
*/
#pragma once

#include <cstdint>

struct BaseUtils {

    static void StaticInit() {
        // init baseIndexMap
        for (int i = 0; i < 256; ++i) {
            baseIndexMap[i] = -1;
        }
        baseIndexMap['A'] = 0;
        baseIndexMap['a'] = 0;
        baseIndexMap['*'] = 0;
        baseIndexMap['C'] = 1;
        baseIndexMap['c'] = 1;
        baseIndexMap['G'] = 2;
        baseIndexMap['g'] = 2;
        baseIndexMap['T'] = 3;
        baseIndexMap['t'] = 3;
    }

    static int baseIndexMap[256];

    // uint8_t转碱基字符
    static const char cBaseToChar[16];

    // 该操作符是否消耗read的碱基
    static bool consumeReadBases(char cigar) { return cigar == 'M' || cigar == '=' || cigar == 'X' || cigar == 'I' || cigar == 'S'; }

    // 该操作符是否消耗参考基因组的碱基
    static bool consumeRefBases(char cigar) { return cigar == 'M' || cigar == '=' || cigar == 'X' || cigar == 'D' || cigar == 'N'; }

    /**
     * Converts a simple base to a base index
     *
     * @param base [AaCcGgTt]
     * @return 0, 1, 2, 3, or -1 if the base can't be understood
     */
    static inline int simpleBaseToBaseIndex(const char base) {
        // we want to make sure we treat the base as an unsigned byte....so that we can access this array with it.
        return baseIndexMap[(uint8_t)base];
    }

    static bool basesAreEqual(const char base1, const char base2) {
        return simpleBaseToBaseIndex(base1) == simpleBaseToBaseIndex(base2);
    }
};