contract ProductionBoiler is BasicAuth
{

    struct Boiler
    {
        uint m_Expire;
        uint32[] m_Chips;
    }

    mapping(address => mapping(uint => Boiler)) g_Boilers;

    bool g_Synced = false;
    function SyncOldData(OldProductionBoiler oldBoiler, address[] accounts) external CreatorAble
    {
        require(!g_Synced);
        g_Synced = true;
        for (uint i=0; i<accounts.length; i++)
        {
            address acc = accounts[i];
            for (uint idx=0; idx<3; idx++)
            {
                (uint expire, uint32[] memory chips) = oldBoiler.GetBoilerInfo(acc,idx);
                if (expire == 0) continue;
                g_Boilers[acc][idx].m_Expire = expire;
                g_Boilers[acc][idx].m_Chips = chips;
            }
        }
    }

    //=========================================================================
    function IsBoilerValid(address acc, uint idx) external view returns(bool)
    {
        Boiler storage obj = g_Boilers[acc][idx];
        if (obj.m_Chips.length > 0) return false;
        return true;
    }

    function IsBoilerExpire(address acc, uint idx) external view returns(bool)
    {
        Boiler storage obj = g_Boilers[acc][idx];
        return obj.m_Expire <= now;
    }

    //=========================================================================

    function GenerateChips(address acc, uint idx, uint cd, uint32[] chips) external AuthAble OwnerAble(acc)
    {
        Boiler storage obj = g_Boilers[acc][idx];
        obj.m_Expire = cd+now;
        obj.m_Chips = chips;
    }

    function CollectChips(address acc, uint idx) external AuthAble OwnerAble(acc) returns(uint32[] chips)
    {
        Boiler storage obj = g_Boilers[acc][idx];
        chips = obj.m_Chips;
        delete g_Boilers[acc][idx];
    }

    function GetBoilerInfo(address acc, uint idx) external view returns(uint, uint32[])
    {
        Boiler storage obj = g_Boilers[acc][idx];
        return (obj.m_Expire,obj.m_Chips);
    }

}
function IsBoilerValid(address acc, uint idx) external view returns(bool)
{
    Boiler storage obj = g_Boilers[acc][idx];
    if (obj.m_Chips.length > 0) return false;
    return true;
}

//=========================================================================