"""Narrow project creation surface for Core-owned agent operations."""

from src.domain.admin.repository import SubscriptionPlanRepository
from src.domain.billing.plan_quota_service import PlanQuotaService
from src.domain.billing.repository import SubscriptionRepository
from src.domain.projects.repository import (
    ProjectEnvVarRepository,
    ProjectJobOutboxRepository,
    ProjectRepoRepository,
    ProjectRepository,
    ProjectSettingsRepository,
)
from src.domain.projects.service import ProjectService
from src.domain.templates.repository import TemplateRepository
from src.domain.workspaces.repository import WorkspaceRepository


class AgentProjectFacade:
    def __init__(self, db, workspaces):
        self.projects = ProjectRepository(db)
        self.quota = PlanQuotaService(
            WorkspaceRepository(db), SubscriptionRepository(db), SubscriptionPlanRepository(db)
        )
        self.service = ProjectService(
            self.projects,
            ProjectRepoRepository(db),
            ProjectSettingsRepository(db),
            ProjectEnvVarRepository(db),
            workspaces,
            self.quota,
            ProjectJobOutboxRepository(db),
            TemplateRepository(db),
        )

    async def create(self, grant, body, project_id, workspace_id):
        return await self.service.create_project(
            workspace_id=workspace_id,
            user_id=grant.created_by,
            project_id=project_id,
            name=body.name,
            project_type=body.project_type,
            description=body.description,
            # start_build already requires a full user_prompt from the agent;
            # the interactive discovery Q&A this would otherwise seed is never
            # walked/completed outside the Dashboard's own UI, which would
            # permanently block every future start_build on the project.
            skip_discovery=True,
        )
