contract FDTNFT is ERC721Tradable2{
    using StringsUtil for string;
    using SafeMath for uint256;

    string public metaURI;
    mapping(address=>uint256) public attrTokenids;
    mapping(address=>string) public attrImgs; 
    


    constructor(address _proxyRegistryAddress)
        ERC721Tradable2("Freedom Trucker", "FDT", _proxyRegistryAddress)
    {
        metaURI = "https://storageapi.fleek.co/3c633711-175b-4cef-83cb-5404e7fe2cc0-bucket/nft/";
    }

    // core feature: mint
    function mintByUser() public {
        _mintTo(_msgSender());
    }

    // public get motheds
    function baseTokenURI() public view override returns (string memory) {
        return metaURI;
    }


    // TODO: set metaURI only by owner
    function setMetaURI(string calldata _metaURI) public onlyOwner {
        require(bytes(_metaURI).length > 0, "param error: meta URI is empty");
        metaURI = _metaURI;
    }

    function addWhite(address[] calldata addrs,uint256[] calldata tokenIds,string[] calldata imgs) public onlyOwner {
        require(addrs.length>0 && addrs.length<501,"array too large");
        require(addrs.length==tokenIds.length && addrs.length==imgs.length,"args err");
        
        for(uint256 i = 0; i< addrs.length;i++){
            require(attrTokenids[addrs[i]]==0,"err:address had set");
            require(!_exists(tokenIds[i]),"err:tokenId had mint");
            attrTokenids[addrs[i]] = tokenIds[i];
            attrImgs[addrs[i]] = imgs[i];
        }
        
    }
    function removeWhite(address addr) public onlyOwner {
        require(attrTokenids[addr]> 0,"err:address had not set");
        require(!_exists(attrTokenids[addr]),"err:addr mapped tokenId had mint");
        attrTokenids[addr] = 0;
        attrImgs[addr] = "";
    }

    // private methods
    function _getTokenId(address _to) internal view override returns (uint256){
        require(attrTokenids[_to]>0,"no set white");
        return attrTokenids[_to];
    }
    function _getImg(uint256 _tokenId) internal view override returns (string memory){
        return attrImgs[ownerOf(_tokenId)];
    }
}
function setMetaURI(string calldata _metaURI) public onlyOwner {
    require(bytes(_metaURI).length > 0, "param error: meta URI is empty");
    metaURI = _metaURI;
}

// TODO: set metaURI only by owner