contract ServiceStationBase {

    // Reference to contract tracking NFT ownership
    ERC721 public nonFungibleContract;

    struct Tune{
        uint256 startChange;
        uint256 rangeChange;
        uint256 attChange;
        bool plusMinus;
        bool replace;
        uint128 price;
        bool active;
        uint64 model;
    }
    Tune[] options;
    
   
    
    /// @dev Returns true if the claimant owns the token.
    /// @param _claimant - Address claiming to own the token.
    /// @param _tokenId - ID of token whose ownership to verify.
    function _owns(address _claimant, uint256 _tokenId) internal view returns (bool) {
        return (nonFungibleContract.ownerOf(_tokenId) == _claimant);
    }
  
    /// @dev Calls the NFT Contract with the tuned attributes 
    function _tune(uint256 _newattributes, uint256 _tokenId) internal {
    nonFungibleContract.tuneLambo(_newattributes, _tokenId);
    }
    
    function _changeAttributes(uint256 _tokenId,uint256 _optionIndex) internal {
    
    //Get model from token
    uint64 model = nonFungibleContract.getLamboModel(_tokenId);
    //throw if tune option is not made for model
    require(options[_optionIndex].model==model);
    
    //Get original attributes
    uint256 attributes = nonFungibleContract.getLamboAttributes(_tokenId);
    uint256 part=0;
    
    //Dissect for options
    part=(attributes/(10 ** options[_optionIndex].startChange)) % (10 ** options[_optionIndex].rangeChange);
    //part=1544;
    //Change attributes & verify
    //Should attChange be added,subtracted or replaced?
    if(options[_optionIndex].replace == false)
        {
            
            //change should be added
            if(options[_optionIndex].plusMinus == false)
            {
                //e.g. if range = 4 then value can not be higher then 9999 - overflow check
                require((part+options[_optionIndex].attChange)<(10**options[_optionIndex].rangeChange));
                //add to attributes
                attributes=attributes+options[_optionIndex].attChange*(10 ** options[_optionIndex].startChange);
            }
            else{
                //do some subtraction
                //e.g. value must be greater then 0
                require(part>options[_optionIndex].attChange);
                //substract from attributes 
                attributes-=options[_optionIndex].attChange*(10 ** options[_optionIndex].startChange);
            }
        }
    else
        {
            //do some replacing
            attributes=attributes-part*(10 ** options[_optionIndex].startChange);
            attributes+=options[_optionIndex].attChange*(10 ** options[_optionIndex].startChange);
        }
    
  
   
    //Tune Lambo in NFT contract
    _tune(uint256(attributes), _tokenId);
       
        
    }
    
    
}
/// @title ServiceStationBase core
/// @dev Contains models, variables, and internal methods for the ServiceStation.
function _tune(uint256 _newattributes, uint256 _tokenId) internal {
nonFungibleContract.tuneLambo(_newattributes, _tokenId);
}

/// @dev Calls the NFT Contract with the tuned attributes 