// SPDX-License-Identifier: MIT
// Version of the Solidity compiler to be used for compilation
pragma solidity ^0.8.9;
// Contract definition for IfElseExample
contract IfElseExample {
// Enumerated type to represent different request states
enum requestState {
created, // Request state: Created
approved, // Request state: Approved
provisioned,// Request state: Provisioned
rejected, // Request state: Rejected
deleted, // Request state: Deleted
none // Request state: None (default)
}
/**
* @dev Function for state management based on the provided state value.
* @param _state The integer value representing a request state.
* @return result An integer result indicating the outcome of state management:
* - 1 if the provided state is equal to 'created'.
* - 2 if the provided state is equal to 'approved' or 'provisioned'.
* - 3 if the provided state is none of the above, or if it's set to 'none'.
*/
function StateManagement(uint8 _state) public returns (int result) {
// Convert the provided integer state value to the requestState enum
requestState currentState = requestState(_state);
// Check if the currentState is equal to 'created' (requestState 1)
if (currentState == requestState(1)) {
result = 1; // Set the result to 1
}
// Check if the currentState is equal to 'approved' or 'provisioned'
else if ((currentState == requestState.approved) || (currentState == requestState.provisioned)) {
result = 2; // Set the result to 2
}
// Handle all other cases, including 'rejected', 'deleted', and 'none'
else {
currentState == requestState.none; // Set currentState to 'none' (default)
result = 3; // Set the result to 3
}
}
}
//Deploy: