// File: contracts/managers/airdrop/CharityCertificateManager.sol



// SPDX-License-Identifier: MIT

pragma solidity 0.8.2;

import "@openzeppelin/contracts/utils/introspection/ERC165.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "../ERC721/ERC721ProjectApproveTransferManager.sol";
import "../project-token-uri-manager/ProjectTokenURIManager.sol";

interface IProject {
    function managerSetTokenURIPrefix(string calldata prefix) external;

    function managerSetApproveTransfer(bool enabled) external;

    function managerMintBatch(address[] calldata recipients, string[] calldata uris)
        external
        returns (uint256[] memory tokenIds);
}

/**
 * Implement this if you want your manager to approve a transfer
 */
contract CharityCertificateManager is ERC721ProjectApproveTransferManager, Ownable {
    bool public transferable;
    IProject public project;

    event LogSetTransferable(bool transferable);
    event LogSetTokenURIPrefix(string prefix);

    constructor(address _project) {
        require(_project != address(0), "bad project");
        project = IProject(_project);
        setTransferable(false);
    }

    /**
     * @dev Set whether or not the project will check the manager for approval of token transfer
     */
    function setApproveTransfer(address _project, bool _enabled) public override onlyOwner {
        require(_project == address(project), "bad _project");
        project.managerSetApproveTransfer(_enabled);
    }

    function setTokenURIPrefix(string calldata _tokenURIPrefix) external onlyOwner {
        project.managerSetTokenURIPrefix(_tokenURIPrefix);
        emit LogSetTokenURIPrefix(_tokenURIPrefix);
    }

    function setTransferable(bool _transferable) public onlyOwner {
        transferable = _transferable;
        emit LogSetTransferable(_transferable);
    }

    function mintCertificates(address[] calldata receivers, string[] calldata usernames)
        external
        onlyOwner
        returns (uint256[] memory tokenIds)
    {
        return project.managerMintBatch(receivers, usernames);
    }

    /**
     * @dev Called by project contract to approve a transfer
     */
    function approveTransfer(
        address from,
        address, /* to */
        uint256 /* tokenId */
    ) external view override returns (bool) {
        if (from == address(0)) {
            return true;
        }
        return transferable;
    }
}

// File: contracts/managers/ERC721/ERC721ProjectApproveTransferManager.sol



// SPDX-License-Identifier: MIT

pragma solidity 0.8.2;

import "./IERC721ProjectApproveTransferManager.sol";

import "@openzeppelin/contracts/utils/introspection/ERC165.sol";

/**
 * Implement this if you want your manager to approve a transfer
 */
abstract contract ERC721ProjectApproveTransferManager is IERC721ProjectApproveTransferManager, ERC165 {
    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
        return
            interfaceId == type(IERC721ProjectApproveTransferManager).interfaceId ||
            super.supportsInterface(interfaceId);
    }
}

// File: contracts/managers/project-token-uri-manager/ProjectTokenURIManager.sol



// SPDX-License-Identifier: MIT

pragma solidity 0.8.2;

import "./IProjectTokenURIManager.sol";
import "@openzeppelin/contracts/utils/introspection/ERC165.sol";

/**
 * @dev Implement this if you want your manager to have overloadable URI's
 */
abstract contract ProjectTokenURIManager is IProjectTokenURIManager, ERC165 {
    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
        return interfaceId == type(IProjectTokenURIManager).interfaceId || super.supportsInterface(interfaceId);
    }
}

// File: @openzeppelin/contracts/utils/introspection/ERC165.sol



// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "./IERC165.sol";

/**
 * @dev Implementation of the {IERC165} interface.
 *
 * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
 * for the additional interface id that will be supported. For example:
 *
 * ```solidity
 * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
 *     return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
 * }
 * ```
 *
 * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
 */
abstract contract ERC165 is IERC165 {
    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        return interfaceId == type(IERC165).interfaceId;
    }
}

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



// SPDX-License-Identifier: MIT

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 () {
        address msgSender = _msgSender();
        _owner = msgSender;
        emit OwnershipTransferred(address(0), msgSender);
    }

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

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        require(owner() == _msgSender(), "Ownable: caller is not the owner");
        _;
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions anymore. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby removing any functionality that is only available to the owner.
     */
    function renounceOwnership() public virtual onlyOwner {
        emit OwnershipTransferred(_owner, address(0));
        _owner = 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");
        emit OwnershipTransferred(_owner, newOwner);
        _owner = newOwner;
    }
}

// File: contracts/managers/ERC721/IERC721ProjectApproveTransferManager.sol



// SPDX-License-Identifier: MIT

pragma solidity 0.8.2;

import "@openzeppelin/contracts/utils/introspection/IERC165.sol";

/**
 * Implement this if you want your manager to approve a transfer
 */
interface IERC721ProjectApproveTransferManager is IERC165 {
    /**
     * @dev Set whether or not the project will check the manager for approval of token transfer
     */
    function setApproveTransfer(address project, bool enabled) external;

    /**
     * @dev Called by project contract to approve a transfer
     */
    function approveTransfer(
        address from,
        address to,
        uint256 tokenId
    ) external returns (bool);
}

// File: @openzeppelin/contracts/utils/introspection/IERC165.sol



// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC165 standard, as defined in the
 * https://eips.ethereum.org/EIPS/eip-165[EIP].
 *
 * Implementers can declare support of contract interfaces, which can then be
 * queried by others ({ERC165Checker}).
 *
 * For an implementation, see {ERC165}.
 */
interface IERC165 {
    /**
     * @dev Returns true if this contract implements the interface defined by
     * `interfaceId`. See the corresponding
     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
     * to learn more about how these ids are created.
     *
     * This function call must use less than 30 000 gas.
     */
    function supportsInterface(bytes4 interfaceId) external view returns (bool);
}

// File: contracts/managers/project-token-uri-manager/IProjectTokenURIManager.sol



// SPDX-License-Identifier: MIT

pragma solidity 0.8.2;

import "@openzeppelin/contracts/utils/introspection/IERC165.sol";

/**
 * @dev Implement this if you want your manager to have overloadable URI's
 */
interface IProjectTokenURIManager is IERC165 {
    /**
     * Get the uri for a given project/tokenId
     */
    function tokenURI(address project, uint256 tokenId) external view returns (string memory);
}

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



// SPDX-License-Identifier: MIT

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) {
        this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
        return msg.data;
    }
}