package com.correx.core.approvals

import com.correx.core.events.types.ProjectId
import com.correx.core.events.types.StageId
import kotlinx.serialization.Serializable

@Serializable
sealed interface GrantScope {
    // toolName binds this grant to a specific operation kind (e.g. "shell", "write_file").
    // A null toolName is rejected at grant-creation time; it is kept nullable here only
    // for backward-compatible deserialization of legacy events. Every operator-creatable
    // scope is tool-bound so a grant can never become a blanket "approve everything"
    // (that is YOLO mode, configured separately).
    @Serializable data class SESSION(val toolName: String? = null) : GrantScope
    @Serializable data class STAGE(val stageId: StageId) : GrantScope

    /** Auto-approve [toolName] for any session whose workspace resolves to [projectId]. */
    @Serializable data class PROJECT(val projectId: ProjectId, val toolName: String? = null) : GrantScope

    /** Auto-approve [toolName] for every session on this machine (the widest scope). */
    @Serializable data class GLOBAL(val toolName: String? = null) : GrantScope
}
