contract RandomShuffleSpirits is VRFConsumerBase {
    
    bytes32 internal keyHash;
    uint256 internal fee;
    
    uint256 public randomResult;

    bool private _randomnessSet;

    uint256 public totalSupply = 9054;

    string public IPFS_WinnersToIdDistribution = "QmbQLKDfHXVc2p9EBj9hoKqEDx6KWuQrKzN887UL6Yn1fy";
    
    string public IPFS_SpiritsTraitsToDistribute = "Qmc8byM66RXfzvBVtLaifZkFyr1cKqXXdownBEb4DiNPRn";

    bytes32 public hashSpiritsPreShuffle = 0x5c4d1087075ee1ba88e39eb27cce185743e78030762bbc73bcb6ea5a5310f892;
    

    

    constructor() 
        VRFConsumerBase( //Mainnet
            0xf0d54349aDdcf704F77AE15b96510dEA15cb7952, // VRF Coordinator
            0x514910771AF9Ca656af840dff83E8264EcF986CA  // LINK Token
        )
    {
        keyHash = 0xAA77729D3466CA35AE8D28B3BBAC7CC36A5031EFDC430821C02BC31A238AF445;
        fee = 2 * 10 ** 18; // 
    }
    
    /** 
     * Requests randomness 
     */
    function getRandomNumber() public returns (bytes32 requestId) {
        require(!_randomnessSet,"Set");
        require(LINK.balanceOf(address(this)) >= fee, "No Link");
        _randomnessSet = true;
        return requestRandomness(keyHash, fee);
    }

    function hashSpiritsMetadataPreRandomShuffle(uint8[7][9054] calldata metadata) public pure returns (bytes32) {
        bytes32 hash = keccak256(abi.encodePacked(metadata));
        return hash;
        
    }

    function RandomShuffleSpiritsIds() public view returns(uint256[9054] memory) {
        uint tempRandom = randomResult;

        uint256[9054] memory numberArr;

        for (uint256 i = 0; i < numberArr.length; i++) {
            numberArr[i] = i + 1574;
        }

        for (uint256 i = 0; i < numberArr.length; i++) {
            uint256 n = i + uint256(keccak256(abi.encodePacked(tempRandom++))) % (numberArr.length - i);
            uint256 temp = numberArr[n];
            numberArr[n] = numberArr[i];
            numberArr[i] = temp;
        }
        return numberArr;

    }

    /**
     * Callback function used by VRF Coordinator
     */
    function fulfillRandomness(bytes32 requestId, uint256 randomness) internal override {
        randomResult = randomness;
    }


}
function fulfillRandomness(bytes32 requestId, uint256 randomness) internal override {
        randomResult = randomness;
    }
/**
 * Callback function used by VRF Coordinator
 */