#ifndef YC_MODEL_H
#define YC_MODEL_H

#include "types.h"


typedef enum
{
    YC_OK = 0,
    YC_ERR_NULL = -1,
    YC_ERR_RANGE = -2,
    YC_ERR_NOT_FOUND = -3
} YC_result_t;


typedef enum
{
    YC_INPUT_TYPE_KI = 0,
    YC_INPUT_TYPE_SINYX = 1,
    YC_INPUT_TYPE_DPYX = 2,
    YC_INPUT_TYPE_UIN8 = 3
} YC_input_type_t;

/* 160×160 屏底栏约在 y=size_y-16；行高≈ascii_height+row_space(14)，9 行末行会与页码区重叠 */
#define YC_ITEMS_PER_PAGE (8)
typedef struct model_t model_t;
typedef struct model_t {
    const uint8_t *topName;
    uint16_t itemNum;
    uint16_t group;
    uint16_t page;
    uint16_t attrib;
    uint16_t cpuPara;
    uint8_t empty;
} model_t;

void Model_Init(model_t *model);


/* 当前页实际行数（末页可能不足 YC_ITEMS_PER_PAGE） */
uint16_t YC_Model_RowsOnCurrentPage(const model_t *model);

/* 全局第 ordinal 个可显示通道对应的 g_tYcIndexTab 下标；失败返回 0xFFFF */
uint16_t YC_Model_TableIndexForOrdinal(uint16_t attrib, uint16_t ordinal);

/* 当前页第 row 行（0 起）对应的全局序数 */
uint16_t YC_Model_OrdinalForRow(const model_t *model, uint8_t rowOnPage);

uint32_t YC_Table_GetRgb(uint16_t tableIndex);
uint8_t YC_Table_GetWidth(uint16_t tableIndex);
uint8_t YC_Table_GetDotBits(uint16_t tableIndex);

const uint8_t *YC_GetNamePtr(const model_t *model, uint16_t inputIndex);
uint8_t YC_Input_GetType(uint16_t inputIndex);
uint8_t YC_Input_GetState(uint16_t cpuPara, uint16_t inputIndex);
YC_result_t YC_Input_FormatState(uint8_t inputType, uint8_t state, uint8_t *buf, size_t bufSize);
#endif