#include "protocol.hpp"
#include "gobotrpc.hpp"
#include <stdint.h>

uint32_t getRpcRequestCompleteMask(RPCNumber rpcNum) {
    switch (rpcNum) {
        case Get_Info:          return 0b00000000000000000000000000000000;
        case Home:              return 0b00000000000000000000000000000011;
        case Move_Step:         return 0b00000000000000000000000000111111;
        case Move_XY:           return 0b00000000000000000000000000111111;
        case Set_Padding:       return 0b00000000000000001101111110111111;
        case Release_Motors:    return 0b00000000000000000000000001111111;
        case Drop_Stone:        return 0b00000000000000000000000000000000;
        case Get_Stone_Status:  return 0b00000000000000000000000000000000;
        case Move_Z_Axis:       return 0b00000000000000000000000000000001;
        case Set_Vacum:         return 0b00000000000000000000000000000001;
        default:                return 0b00000000000000000000000000000000;
    }
}

uint32_t getRpcResponseCompleteMask(RPCNumber rpcNum) {
    switch (rpcNum) {
        case Get_Info:          return 0b00001111111111111111111111111111;
        case Home:              return 0b00000000000000000000000000111111;
        case Move_Step:         return 0b00000000000000000000000000000000;
        case Move_XY:           return 0b00000000000000000000000000000000;
        case Set_Padding:       return 0b00000000000000000000000000000000;
        case Release_Motors:    return 0b00000000000000000000000000000000;
        case Drop_Stone:        return 0b00000000000000000000000000000000;
        case Get_Stone_Status:  return 0b00000000000000000000000000000000;
        case Move_Z_Axis:       return 0b00000000000000000000000000000000;
        case Set_Vacum:         return 0b00000000000000000000000000000000;
        default:                return 0b00000000000000000000000000000000;
    }
}

uint32_t ERROR_MASK = 0b00000000000000000000000000000000;

FrameSubmitionResult getPackageStatus(RPC_RX_PackageSlot * package) {
    
    uint32_t mask;

    switch (package->type) {
        case REQUEST:
            mask = getRpcRequestCompleteMask(package->rpcNum);
            break;
        case RESPONSE_RPC:
            mask = getRpcResponseCompleteMask(package->rpcNum);
            break;
        case ERROR:
            mask = ERROR_MASK;
            break;
        default:
            return ERROR_INVALID_RPC_TYPE;
    };

    uint32_t masked_bits = package->used_bit_masked & mask;

    if(masked_bits == mask) {
        return COMPLEATE;
    }

    return PENDING;
}