class Project extends Service('hn.enterprise')
    constructor: ($q, e, ProjectType, NerdUser, ProjectArchive, Session, NerdReview) ->

        ###*
        # Which tabs should this project have on the project details page?
        # @method enabledTabs
        # @param project
        ###
        @enabledTabs = (project) ->
            PENDING = @PENDING = 'pending'
            ACTIVE = @ACTIVE = 'active'
            CLOSED = @CLOSED = 'closed'

            tabStatus = {
                details: PENDING
                invites: PENDING
                bids: PENDING
                workspace: PENDING
            }

            # Details Tab
            tabStatus.details = ACTIVE

            # Invite Tab
            if project.status in [
                e.ProjectStatus.OUT_FOR_BID,
                e.ProjectStatus.OUT_FOR_PRIVATE_BID,
                e.ProjectStatus.PROPOSAL
                ]
                tabStatus.invites = ACTIVE

            if project.status in [
                e.ProjectStatus.BIDDING_CLOSED,
                e.ProjectStatus.ACTIVE,
                e.ProjectStatus.BUSINESS_APPROVAL_REQUIRED,
                e.ProjectStatus.COMPLETED,
                e.ProjectStatus.EXPIRED,
                e.ProjectStatus.WITHDRAWN_PROPOSAL,
                e.ProjectStatus.REJECTED_PROPOSAL,
                e.ProjectStatus.EXPIRED_PROPOSAL
                ]
                tabStatus.invites = CLOSED

            # Bid Tab
            if project.status in [
                e.ProjectStatus.OUT_FOR_BID,
                e.ProjectStatus.OUT_FOR_PRIVATE_BID,
                e.ProjectStatus.PROPOSAL
                ]
                tabStatus.bids = ACTIVE

            if project.status in [
                e.ProjectStatus.BIDDING_CLOSED,
                e.ProjectStatus.ACTIVE,
                e.ProjectStatus.BUSINESS_APPROVAL_REQUIRED,
                e.ProjectStatus.COMPLETED,
                e.ProjectStatus.EXPIRED,
                e.ProjectStatus.WITHDRAWN_PROPOSAL,
                e.ProjectStatus.REJECTED_PROPOSAL,
                e.ProjectStatus.EXPIRED_PROPOSAL
                ]
                tabStatus.bids = CLOSED

            # Workspace Tab
            if project.status in [
                e.ProjectStatus.ACTIVE,
                e.ProjectStatus.BUSINESS_APPROVAL_REQUIRED,
                ]
                tabStatus.workspace = ACTIVE

            if project.status in [
                e.ProjectStatus.COMPLETED,
                e.ProjectStatus.EXPIRED,
                e.ProjectStatus.WITHDRAWN_PROPOSAL,
                e.ProjectStatus.REJECTED_PROPOSAL,
                e.ProjectStatus.EXPIRED_PROPOSAL
                ]
                tabStatus.workspace = CLOSED

            return tabStatus

        @getProjectArchivePreview = (projectArchiveId) ->
            return ProjectArchive.project.getOneForSharingView({
                id: projectArchiveId
                sharing_level: e.ProjectArchiveSharingLevel.RESTRICTED
            }).$promise

        @getNerdsPastProjectsWithReviews = (nerd) ->
            df = $q.defer()
            projectsPromise = ProjectArchive.project.getManyForNerdUser(
                nerd_user_id: nerd.id
                project_status: e.ProjectStatus.COMPLETED
            ).$promise

            reviewsPromise = NerdReview.getManyForNerdUser(nerd_user_id: nerd.id).$promise

            $q.all([projectsPromise, reviewsPromise]).then((arr) ->
                [archives, reviews] = arr
                projects = archives.reverse()
                reviewMap = {}
                _.each(reviews, (review) ->
                    reviewMap[review.project_id] = review if review.project_id
                )
                _.each(projects, (project) ->
                    project.nerd_review = reviewMap[project.id] or null
                    return
                )
                df.resolve(projects)
            )
            return df.promise


        @getSampleNerd = ->
            return {
            "about_me": "Results oriented strategic consultant with experience in Sales, Marketing, Market Research, Consumer Packaged Goods, Health Care, Start-ups, Digital Media, and the Non Profit sectors.  Experience working with large multinational corporations as well as startups within those organizations.  Committed to delivering projects that drive strategic initiatives across functional business areas including Operations, Sales, Product, IT, and Customer Service.\r<br>\n\r<br>\nSpecialties: Business Development, current state analysis, future state architecture, process improvement, ROI analysis, business case justification, writing, research, strategy, digital marketing, project management, portfolio analysis, stakeholder analysis, financial reporting, training, business requirements documentation, change management/business transformation, service model transformation, relationship building, territory cultivation, marketing, sales, & fundraising.",
            "created_at": "2015-01-21T16:28:09+00:00",
            "encoded_id": "45545302548459197536",
            "first_name": "Shannon",
            "full_name": "Shannon M.",
            "graduation_year": "2013",
            "id": "182457bf",
            "image_url": "https://app.staging.hourlynerd.com/photo/37223/11",
            "is_accredited": true,
            "last_name": "M.",
            "nerd_availability": {
                "is_available": true,
                "is_available_for_private_projects": false
            },
            "nerd_profile": {
                "business_unit_project_types_recommended_for": null,
                "business_units_recommended_for": null,
                "education": [
                    {
                        "began_at": "2013-01-01T12:00:00+00:00",
                        "degree": "Green Belt",
                        "ended_at": "2013-01-01T12:00:00+00:00",
                        "school_name": "Purdue University"
                    },
                    {
                        "began_at": "1996-01-01T12:00:00+00:00",
                        "degree": "BA",
                        "ended_at": "1999-01-01T12:00:00+00:00",
                        "school_name": "Columbia University in the City of New York"
                    },
                    {
                        "began_at": null,
                        "degree": "",
                        "ended_at": null,
                        "school_name": "Middletown HS South"
                    },
                    {
                        "began_at": null,
                        "degree": "MBA",
                        "ended_at": null,
                        "school_name": "Vanderbilt University - Owen Graduate School of Management"
                    }
                ],
                "experience": [
                    {
                        "began_at": "2012-06-01T12:00:00+00:00",
                        "company_name": "Weight Watchers",
                        "description": "Work with Sales, Sales Operations, Marketing, IT, and Field to improve B2B products and delivery.",
                        "ended_at": "2013-10-01T12:00:00+00:00",
                        "title": "Project Management Consultant, B2B & Health Solutions"
                    },
                    {
                        "began_at": "2012-01-01T12:00:00+00:00",
                        "company_name": "Pro Mujer",
                        "description": "Donor development, target analysis, new donor research.",
                        "ended_at": "2012-01-01T12:00:00+00:00",
                        "title": "Development"
                    },
                    {
                        "began_at": "2010-09-01T12:00:00+00:00",
                        "company_name": "Avon",
                        "description": "Innovation Reporting (Financial forecasting for new beauty products)<br>\nSoftware Training<br>\nNPD project automation (document business requirements for different regions globally)",
                        "ended_at": "2011-11-01T12:00:00+00:00",
                        "title": "Consultant, Project Management, New Product Development"
                    },
                    {
                        "began_at": "2009-03-01T12:00:00+00:00",
                        "company_name": "SM Consulting LLC",
                        "description": "Strategic Partnerships<br>\nMarketing <br>\nMarket Analysis<br>\nConsumer Collateral<br>\nBusiness Development<br>\nTerritory assessment<br>\nMarket Research<br>\nPipeline Analysis<br>\nNon Profit Development/Fundraising &amp; Event Planning<br>\nMicrofinance (LATAM)<br>\nProject Management<br>\nDonor Development<br>\nSales Analysis<br>\nOrganizational Analysis <br>\nProcess Improvement<br>\nImplementation<br>\nChange Management<br>\nOpportunity Analysis <br>\nForecasting models<br>\nStrategic Planning/Annual Operating Planning<br>\nPerformance Analysis <br>\nKPI Creation and Analysis",
                        "ended_at": null,
                        "title": "Strategic Consulting & Project Development"
                    },
                    {
                        "began_at": "2007-11-01T12:00:00+00:00",
                        "company_name": "SM Consulting, LLC",
                        "description": "Business Development and Marketing collateral for CPGs, Pharma, and Startups",
                        "ended_at": "2010-09-01T12:00:00+00:00",
                        "title": "Business Development & Marketing Consultant"
                    },
                    {
                        "began_at": "2005-05-01T12:00:00+00:00",
                        "company_name": "eMarketer",
                        "description": "Sold Digital Market Research to Omnicom, WPP, Aegis, and independent advertising agencies globally.",
                        "ended_at": "2007-10-01T12:00:00+00:00",
                        "title": "Business Development Manager"
                    },
                    {
                        "began_at": "2003-06-01T12:00:00+00:00",
                        "company_name": "FedEx Services",
                        "description": "Digital marketing<br>\nVendor management<br>\nBudget allocation<br>\nLoyalty marketing incentive program (Sept-Dec)",
                        "ended_at": "2003-12-01T12:00:00+00:00",
                        "title": "MBA Intern"
                    }
                ],
                "review_summary": {
                    "average_communication_rating": 0,
                    "average_expertise_rating": 0,
                    "average_overall_rating": 0,
                    "average_presentation_rating": 0,
                    "average_quality_rating": 0,
                    "average_timeliness_rating": 0,
                    "nerd_user_id": "182457bf"
                }
            },
            "nerd_stats": {
                "completed_project_count": 1
            },
            "organization_id": "dd084748",
            "rating": 0,
            "school_image_url": "https://app.staging.hourlynerd.com/photo/4181",
            "school_name": "Owen (Vanderbilt)",
            "small_image_url": "https://app.staging.hourlynerd.com/photo/37223/10",
            "title": "",
            "type": "nerd",
            "user_encoded_id": "45545302548459217705"

            }