import { Action, type ActionSchema } from './Action.js'
import { observed } from '../../decorators/observed.js'

/**
 * Enables retrieving a single resource by its ID.
 * Endpoint: GET /[entity-collection-name]/{id}
 */
export interface ReadActionSchema extends ActionSchema {
  kind: 'read'
  // Association handling (Link IDs vs. Embed) is defined on the
  // data association itself in the Data Modeler.
}

/**
 * Enables retrieving a single resource by its ID.
 * Endpoint: GET /[entity-collection-name]/{id}
 */
export class ReadAction extends Action implements ReadActionSchema {
  @observed() override accessor kind: 'read'

  constructor(state: Partial<ReadActionSchema> = {}) {
    super(state)
    this.kind = 'read'
  }

  override toJSON(): ReadActionSchema {
    return {
      ...(super.toJSON() as ReadActionSchema),
      kind: 'read',
    }
  }

  static isReadAction(action: Action): action is ReadAction {
    return action.kind === 'read'
  }

  static isReadActionSchema(schema: ActionSchema): schema is ReadActionSchema {
    return schema.kind === 'read'
  }
}
