contract PassContractorCreator {
    
    // Address of the pass Dao smart contract
    PassDao public passDao;
    // Address of the Pass Project creator
    PassProjectCreator public projectCreator;
    
    struct contractor {
        // The address of the creator of the contractor
        address creator;
        // The contractor smart contract
        PassContractor contractor;
        // The address of the recipient for withdrawals
        address recipient;
        // True if meta project
        bool metaProject;
        // The address of the existing project smart contract
        PassProject passProject;
        // The name of the project (if the project smart contract doesn't exist)
        string projectName;
        // A description of the project (can be updated after)
        string projectDescription;
        // The unix creation date of the contractor
        uint creationDate;
    }
    // contractors created to work for Pass Dao
    contractor[] public contractors;
    
    event NewPassContractor(address indexed Creator, address indexed Recipient, PassProject indexed Project, PassContractor Contractor);

    function PassContractorCreator(PassDao _passDao, PassProjectCreator _projectCreator) {
        passDao = _passDao;
        projectCreator = _projectCreator;
        contractors.length = 0;
    }

    /// @return The number of created contractors 
    function numberOfContractors() constant returns (uint) {
        return contractors.length;
    }
    
    /// @notice Function to create a contractor smart contract
    /// @param _creator The address of the creator of the contractor
    /// @param _recipient The address of the recipient for withdrawals
    /// @param _metaProject True if meta project
    /// @param _passProject The address of the existing project smart contract
    /// @param _projectName The name of the project (if the project smart contract doesn't exist)
    /// @param _projectDescription A description of the project (can be updated after)
    /// @param _restore True if orders or proposals are to be cloned from other contracts
    /// @return The address of the created contractor smart contract
    function createContractor(
        address _creator,
        address _recipient, 
        bool _metaProject,
        PassProject _passProject,
        string _projectName, 
        string _projectDescription,
        bool _restore) returns (PassContractor) {
 
        PassProject _project;

        if (_creator == 0) _creator = msg.sender;
        
        if (_metaProject) _project = PassProject(passDao.MetaProject());
        else if (address(_passProject) == 0) 
            _project = projectCreator.createProject(passDao, _projectName, _projectDescription, 0);
        else _project = _passProject;

        PassContractor _contractor = new PassContractor(_creator, _project, _recipient, _restore);
        if (!_metaProject && address(_passProject) == 0 && !_restore) _project.setProjectManager(address(_contractor));
        
        uint _contractorID = contractors.length++;
        contractor c = contractors[_contractorID];
        c.creator = _creator;
        c.contractor = _contractor;
        c.recipient = _recipient;
        c.metaProject = _metaProject;
        c.passProject = _passProject;
        c.projectName = _projectName;
        c.projectDescription = _projectDescription;
        c.creationDate = now;

        NewPassContractor(_creator, _recipient, _project, _contractor);
 
        return _contractor;
    }
    
}
function createContractor(
        address _creator,
        address _recipient, 
        bool _metaProject,
        PassProject _passProject,
        string _projectName, 
        string _projectDescription,
        bool _restore) returns (PassContractor) {
 
        PassProject _project;

        if (_creator == 0) _creator = msg.sender;
        
        if (_metaProject) _project = PassProject(passDao.MetaProject());
        else if (address(_passProject) == 0) 
            _project = projectCreator.createProject(passDao, _projectName, _projectDescription, 0);
        else _project = _passProject;

        PassContractor _contractor = new PassContractor(_creator, _project, _recipient, _restore);
        if (!_metaProject && address(_passProject) == 0 && !_restore) _project.setProjectManager(address(_contractor));
        
        uint _contractorID = contractors.length++;
        contractor c = contractors[_contractorID];
        c.creator = _creator;
        c.contractor = _contractor;
        c.recipient = _recipient;
        c.metaProject = _metaProject;
        c.passProject = _passProject;
        c.projectName = _projectName;
        c.projectDescription = _projectDescription;
        c.creationDate = now;

        NewPassContractor(_creator, _recipient, _project, _contractor);
 
        return _contractor;
    }
/// @notice Function to create a contractor smart contract
/// @param _creator The address of the creator of the contractor
/// @param _recipient The address of the recipient for withdrawals
/// @param _metaProject True if meta project
/// @param _passProject The address of the existing project smart contract
/// @param _projectName The name of the project (if the project smart contract doesn't exist)
/// @param _projectDescription A description of the project (can be updated after)
/// @param _restore True if orders or proposals are to be cloned from other contracts
/// @return The address of the created contractor smart contract