// SPDX-License-Identifier: MIT
// Copyright (c) 2023 Fellowship

pragma solidity ^0.8.7;

import './PPPCollection.sol';

struct CollectionInfo {
    string name;
    string symbol;
    string baseURI;
    address royaltyReceiver;
}

contract PPPMetaCollection is Ownable {
    address public minter;
    PPPCollection[10] public collection;

    error OnlyMinter();

    constructor(uint256 royaltyPercent, CollectionInfo[10] memory collectionsInfo) {
        // CHECKS
        for (uint256 i = 0; i < 10; i++) {
            CollectionInfo memory info = collectionsInfo[i];
            require(bytes(info.name).length > 0, "All collections must have a name");
            require(bytes(info.symbol).length > 0, "All collections must have a symbol");
            require(bytes(info.baseURI).length > 0, "All collections must have a base URI");
        }

        // EFFECTS + INTERACTIONS
        for (uint256 i = 0; i < 10; i++) {
            CollectionInfo memory info = collectionsInfo[i];
            PPPCollection newCollection = collection[i] = new PPPCollection(
                info.name,
                info.symbol,
                info.baseURI,
                100,
                info.royaltyReceiver,
                royaltyPercent
            );

            newCollection.setMinter(address(this));
            newCollection.transferOwnership(msg.sender);
        }
    }

    // MINTER FUNCTIONS

    function mint(address to, uint256 tokenId) external {
        // CHECKS
        if (msg.sender != minter) revert OnlyMinter();

        // INTERACTIONS
        collection[tokenId / 100].mint(to, tokenId % 100);
    }

    // OWNER FUNCTIONS

    function setMinter(address minter_) external onlyOwner {
        minter = minter_;
    }

    // VIEW FUNCTIONS

    /// @notice Query if a contract implements an interface
    /// @dev Interface identification is specified in ERC-165. This function uses less than 30,000 gas.
    /// @param interfaceId The interface identifier, as specified in ERC-165
    /// @return `true` if the contract implements `interfaceID` and `interfaceID` is not 0xffffffff, `false` otherwise
    function supportsInterface(bytes4 interfaceId) public pure returns (bool) {
        return
            interfaceId == 0x7f5828d0 || // ERC-173 Contract Ownership Standard
            interfaceId == 0x01ffc9a7; // ERC-165 Standard Interface Detection
    }
}
[{"inputs":[{"internalType":"uint256","name":"royaltyPercent","type":"uint256"},{"components":[{"internalType":"string","name":"name","type":"string"},{"internalType":"string","name":"symbol","type":"string"},{"internalType":"string","name":"baseURI","type":"string"},{"internalType":"address","name":"royaltyReceiver","type":"address"}],"internalType":"struct CollectionInfo[10]","name":"collectionsInfo","type":"tuple[10]"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"OnlyMinter","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"collection","outputs":[{"internalType":"contract PPPCollection","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"mint","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"minter","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"minter_","type":"address"}],"name":"setMinter","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"}]