// File: contracts/VenusMetadata.sol



//SPDX-License-Identifier: MIT

pragma solidity ^0.8;

import "@openzeppelin/contracts/access/Ownable.sol";

// :...:!?Y7~~!?J77!~!!5BP5~~P&&&G&&&&&&&&&&#@@@@&@@@@&&@@@@@@@@@&@@@@@@@@@@&@@@@@@@@@@&@@@@@@@@@@
// ::.:5BGJ!~?PP?:.:^7?#&GP~.^?B@#@@@@@@@@@@#@@@@@@@@@&&@@@@@@@@@&&@@@@@@@@@#@@@@@@@@@@B@@@@@@@@@@
// ^^^YPJ?J?YP?:....~Y5##BG?:..:7Y&@@@@@@@@@#@@@@@@@@@&#@@&&##BGPJ?J??7777??75PGGG&@@@@B@@@@@@@@@@
// 7!!77777!!!:...^7G&GBBBG?:^^:::7GBPPGBB##P#BGP555YJ??YJ?7!!~^^::.......::^^!7?JYG#&@B@@@@@@@@@@
// ???????7!!77?YPB&&&P##BJ:..:::^^:~7?J????!J??77!~~~^^^^^::...............:::^^~!7?5GP@@@@@@@@@@
// ~!!7?J5PYP##&&&&##BYY?~^~~~^^~^^^~!!77!77!???777!~^::....................:::::^~!7?Y?G#&@@@@@@&
// ^::::^~!~7JY55PPPY?~~~~!7???77~7777??????!777!7777!~^^:......................:^~~!?J?G#&@@@@@@@
// ~~:...........::^^~^~~~~~~~~~!~!77????JJJ7YYY?7!!~~~^^::....................::^~~7?J?G#&&@@@@@@
// ::^^:......................:::::::^^~~~!7!?JYYYJ?!^::^:::...................:^~!?JYPJ#&&&@@@@@@
// ..::::..............................:::^^^7??JY55Y?~:....................::^!7JJY5PG5&&&&@@@@@@
// ....:::::............................:::^^~!77JYYYY?~^:............::::^^^~~!!!7777?7PB#&@@@@@&
// ......:::..............^^!77!^:.........::^~!7?JY5PY??!^:.........:::::::::^~~!!!77?!5G#&@@@@@@
// .........::...........:^!?7Y5J!~:........:^^!!7?JYYJ?Y?77~::........:::::::^^^^~~~!!~?5B##&@@@@
// .........::.......... .:^~~!!~^^........:::^~!!77777!777??77~^:........::::::.....:::^!J5GBB&@@
// ..........::........... ................:::^^~!!!!!~^^^^^~!777^:.......................:~J5PPB#
// ..........:^:........................:::::^^^~~!!~^^::::::^!77~~^:.....................::~??555
// ...........:~^:...........   ........:::::^^~~!!~^:::.:::^^~~!~!7!^.....................:^!7JYJ
// :...........:~^:..........   .......:::^^^^~~!~^:.........^~^~~!777~:..................::::^^~!
// ~::..........:!~^:::..............::^~~~~~!7!^.............:^~!!!!77!^:...............:::::::::
// #G5?~::.......:~!!~^^:::::::::::^^~!!77??7?7^...............:^~~~^~!~~~^:...............::^^^::
// B###BP57^.......:!7!7!~~~~~^^~~!!!7??JYJ?~~:................:^^~^:::::^^^^::::..........::::^^^
// ###BBBBB5YJ!^:....:^!77?????77!?JJJJ?7!^^:..................:^:::....:::::^::::::..........:::^
// ##&&####PPBBGPJ!:..:.:::^~~!!!~7!~~^^:::....................:::.........::::::^^:::...........:
// ##&&&&&#PB#GPG##GJ~:........::::::::::::..::::::...........::::.............::::^^::::.........
// author: jolan.eth

contract VenusMetadata is Ownable {
    string public CENSORED;
    string public UNCENSORED;

    mapping(uint256 => string) airdropCID;

    constructor() {}

    function setCIDs(string memory censored, string memory uncensored)
        public
        onlyOwner
    {
        CENSORED = censored;
        UNCENSORED = uncensored;
    }

    function setAirdropCID(uint256 id, string memory cid) public onlyOwner {
        airdropCID[id] = cid;
    }

    function generateMetadata(
        uint256 id,
        string memory name,
        bool state
    ) public view returns (string memory) {
        if (id > 250)
            return string(abi.encodePacked("ipfs://", airdropCID[id]));
        else if (id > 0 && id <= 250)
            return
                string(
                    abi.encodePacked(
                        "data:application/json;base64,",
                        _encode(
                            bytes(
                                string(
                                    abi.encodePacked(
                                        "{",
                                        '"name":"',
                                        bytes(name).length > 0
                                            ? name
                                            : string(
                                                abi.encodePacked(
                                                    "The Censored Venus #",
                                                    _serialize(id)
                                                )
                                            ),
                                        '",',
                                        '"description":"The Censored Venus is an NFT collection that explores the theme of nudity censorship in art. This collection was created based on the original artwork painted in oil on canvas (130 x 80 cm) by Pascal Boyart in October 2022.",',
                                        '"image":"ipfs://',
                                        state
                                            ? string(
                                                abi.encodePacked(
                                                    UNCENSORED,
                                                    "/",
                                                    _serialize(id),
                                                    "_uncensored.jpg"
                                                )
                                            )
                                            : string(
                                                abi.encodePacked(
                                                    CENSORED,
                                                    "/",
                                                    _serialize(id),
                                                    "_censored.gif"
                                                )
                                            ),
                                        '",',
                                        '"attributes":[',
                                        "{",
                                        '"trait_type":"Status",',
                                        '"value":"',
                                        state ? "Uncensored" : "Censored",
                                        '"',
                                        "}"
                                        "]",
                                        "}"
                                    )
                                )
                            )
                        )
                    )
                );
        else revert DoNotExist();
    }

    function _toString(uint256 value) private pure returns (string memory) {
        if (value == 0) return "0";

        uint256 digits;
        uint256 tmp = value;

        while (tmp != 0) {
            digits++;
            tmp /= 10;
        }

        bytes memory buffer = new bytes(digits);
        while (value != 0) {
            digits -= 1;
            buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
            value /= 10;
        }

        return string(buffer);
    }

    function _encode(bytes memory data) internal pure returns (string memory) {
        uint256 len = data.length;
        if (len == 0) return "";

        uint256 encodedLen = 4 * ((len + 2) / 3);

        bytes memory result = new bytes(encodedLen + 32);

        bytes
            memory table = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";

        assembly {
            let tablePtr := add(table, 1)
            let resultPtr := add(result, 32)

            for {
                let i := 0
            } lt(i, len) {

            } {
                i := add(i, 3)
                let input := and(mload(add(data, i)), 0xffffff)

                let out := mload(add(tablePtr, and(shr(18, input), 0x3F)))
                out := shl(8, out)
                out := add(
                    out,
                    and(mload(add(tablePtr, and(shr(12, input), 0x3F))), 0xFF)
                )
                out := shl(8, out)
                out := add(
                    out,
                    and(mload(add(tablePtr, and(shr(6, input), 0x3F))), 0xFF)
                )
                out := shl(8, out)
                out := add(
                    out,
                    and(mload(add(tablePtr, and(input, 0x3F))), 0xFF)
                )
                out := shl(224, out)

                mstore(resultPtr, out)

                resultPtr := add(resultPtr, 4)
            }

            switch mod(len, 3)
            case 1 {
                mstore(sub(resultPtr, 2), shl(240, 0x3d3d))
            }
            case 2 {
                mstore(sub(resultPtr, 1), shl(248, 0x3d))
            }

            mstore(result, encodedLen)
        }

        return string(result);
    }

    function _serialize(uint256 _tokenId)
        internal
        pure
        returns (string memory result)
    {
        string memory tmp;
        if (_tokenId < 1000)
            tmp = string(abi.encodePacked("", _toString(_tokenId)));
        if (_tokenId < 100)
            tmp = string(abi.encodePacked("0", _toString(_tokenId)));
        if (_tokenId < 10)
            tmp = string(abi.encodePacked("00", _toString(_tokenId)));

        result = tmp;
    }

    error DoNotExist();
}

// File: @openzeppelin/contracts/access/Ownable.sol



// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)

pragma solidity ^0.8.0;

import "../utils/Context.sol";

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * By default, the owner account will be the one that deploys the contract. This
 * can later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract Ownable is Context {
    address private _owner;

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    constructor() {
        _transferOwnership(_msgSender());
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        _checkOwner();
        _;
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view virtual returns (address) {
        return _owner;
    }

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        require(owner() == _msgSender(), "Ownable: caller is not the owner");
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby disabling any functionality that is only available to the owner.
     */
    function renounceOwnership() public virtual onlyOwner {
        _transferOwnership(address(0));
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        require(newOwner != address(0), "Ownable: new owner is the zero address");
        _transferOwnership(newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}

// File: @openzeppelin/contracts/utils/Context.sol



// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)

pragma solidity ^0.8.0;

/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }
}