#[derive(Clone, Copy, PartialEq, Eq)]
#[repr(u8)]
pub enum Ecall {
    AccountBalance = 0,
    AccountCode = 1,
    AccountCodeSize = 2,
    AccountCodehash = 3,
    EthereumLoad = 4,
    EthereumStore = 5,
    StorageFlushCache = 6,
    BlockBasefee = 7,
    Chainid = 8,
    BlockCoinbase = 9,
    BlockGasLimit = 10,
    BlockNumber = 11,
    BlockTimestamp = 12,
    CallContract = 13,
    ContractAddress = 14,
    Create1 = 15,
    Create2 = 16,
    DelegateCallContract = 17,
    EmitLog = 18,
    EvmGasLeft = 19,
    EvmInkLeft = 20,
    PayForMemoryGrow = 21,
    MsgReentrant = 22,
    MsgSender = 23,
    MsgValue = 24,
    NativeKeccak256 = 25,
    ReadArgs = 26,
    ReadReturnData = 27,
    WriteResult = 28,
    ReturnDataSize = 29,
    StaticCallContract = 30,
    TxGasPrice = 31,
    TxInkPrice = 32,
    TxOrigin = 33,
    ArgsLen = 34,
    Console = 35,
    TransientLoad = 36,
    TransientStore = 37,
    MathAdd = 38,
    MathDiv = 39,
    MathMod = 40,
    MathAddMod = 41,
    MathMulMod = 42,
    ExitEarly = 43,
}

impl TryFrom<u8> for Ecall {
    type Error = u8;

    fn try_from(value: u8) -> Result<Self, Self::Error> {
        match value {
            0 => Ok(Ecall::AccountBalance),
            1 => Ok(Ecall::AccountCode),
            2 => Ok(Ecall::AccountCodeSize),
            3 => Ok(Ecall::AccountCodehash),
            4 => Ok(Ecall::EthereumLoad),
            5 => Ok(Ecall::EthereumStore),
            6 => Ok(Ecall::StorageFlushCache),
            7 => Ok(Ecall::BlockBasefee),
            8 => Ok(Ecall::Chainid),
            9 => Ok(Ecall::BlockCoinbase),
            10 => Ok(Ecall::BlockGasLimit),
            11 => Ok(Ecall::BlockNumber),
            12 => Ok(Ecall::BlockTimestamp),
            13 => Ok(Ecall::CallContract),
            14 => Ok(Ecall::ContractAddress),
            15 => Ok(Ecall::Create1),
            16 => Ok(Ecall::Create2),
            17 => Ok(Ecall::DelegateCallContract),
            18 => Ok(Ecall::EmitLog),
            19 => Ok(Ecall::EvmGasLeft),
            20 => Ok(Ecall::EvmInkLeft),
            21 => Ok(Ecall::PayForMemoryGrow),
            22 => Ok(Ecall::MsgReentrant),
            23 => Ok(Ecall::MsgSender),
            24 => Ok(Ecall::MsgValue),
            25 => Ok(Ecall::NativeKeccak256),
            26 => Ok(Ecall::ReadArgs),
            27 => Ok(Ecall::ReadReturnData),
            28 => Ok(Ecall::WriteResult),
            29 => Ok(Ecall::ReturnDataSize),
            30 => Ok(Ecall::StaticCallContract),
            31 => Ok(Ecall::TxGasPrice),
            32 => Ok(Ecall::TxInkPrice),
            33 => Ok(Ecall::TxOrigin),
            34 => Ok(Ecall::ArgsLen),
            35 => Ok(Ecall::Console),
            36 => Ok(Ecall::TransientLoad),
            37 => Ok(Ecall::TransientStore),
            38 => Ok(Ecall::MathAdd),
            39 => Ok(Ecall::MathDiv),
            40 => Ok(Ecall::MathMod),
            41 => Ok(Ecall::MathAddMod),
            42 => Ok(Ecall::MathMulMod),
            43 => Ok(Ecall::ExitEarly),
            _ => Err(value),
        }
    }
}
