import type {Message} from '@sanity/comlink'

import type {Resource} from '../types'

/**
 * @public
 */
export interface Context_v1 {
  organizationId: string
  /**
   * The URL of the dashboard embedding the current application.
   * Used by the bridge to construct absolute links back into the dashboard,
   * e.g. when opening a resource in a new tab.
   *
   * Optional because older dashboard versions may not provide it — consumers
   * should fall back to `document.referrer` when absent.
   */
  dashboardUrl?: string
  /**
   * Information about the current application
   */
  resource: Resource
  /**
   * All the resources available to the current user
   */
  availableResources: Resource[]
}

/**
 * Message sent to fetch the context of the
 * current application within the dashboard.
 * @public
 */
export interface ContextMessage_v1 extends Message {
  type: 'dashboard/v1/context'
  response: {
    context: Context_v1
  }
}
