     1	import { RestApiResourceError } from '../../../lib/rest-api-errors.js'
     2	import { handleWriteMethodError } from './common.js'
     3	
     4	/**
     5	 * DELETE
     6	 * Permanently deletes a resource.
     7	 * Returns 204 No Content on success, indicating the resource has been removed.
     8	 * This method does not return the deleted resource.
     9	 */
    10	export default async function deleteMethod ({
    11	  params,
    12	  context,
    13	  vars,
    14	  helpers,
    15	  scope,
    16	  scopes,
    17	  runHooks,
    18	  apiOptions,
    19	  pluginOptions,
    20	  scopeOptions,
    21	  scopeName,
    22	  api,
    23	  log
    24	}) {
    25	  // Make the method available to all hooks
    26	  context.method = 'delete'
    27	
    28	  // Set the ID in context
    29	  context.id = params.id
    30	
    31	  // Set scopeName in context (needed for broadcasting)
    32	  context.scopeName = scopeName
    33	
    34	  // Set schema info even for DELETE (needed by storage layer)
    35	  context.schemaInfo = scopes[scopeName].vars.schemaInfo
    36	
    37	  // Transaction handling
    38	  context.transaction = params.transaction ||
    39	      (helpers.newTransaction && !params.transaction ? await helpers.newTransaction() : null)
    40	  context.shouldCommit = !params.transaction && !!context.transaction
    41	  context.db = context.transaction || api.knex.instance
    42	
    43	  try {
    44	    // No payload validation needed for DELETE
    45	
    46	    // Fetch minimal record for authorization and logging
    47	    const minimalRecord = await helpers.dataGetMinimal({
    48	      scopeName,
    49	      context,
    50	      runHooks
    51	    })
    52	
    53	    if (!minimalRecord) {
    54	      throw new RestApiResourceError(
    55	        'Resource not found',
    56	        {
    57	          subtype: 'not_found',
    58	          resourceType: scopeName,
    59	          resourceId: context.id
    60	        }
    61	      )
    62	    }
    63	
    64	    context.originalMinimalRecord = minimalRecord
    65	    context.minimalRecord = minimalRecord
    66	
    67	    // Centralised checkPermissions function
    68	    await scope.checkPermissions({
    69	      method: 'delete',
    70	      originalContext: context,
    71	    })
    72	
    73	    // Before data operations
    74	    await runHooks('beforeDataCall')
    75	    await runHooks('beforeDataCallDelete')
    76	
    77	    // Initialize record context for hooks
    78	    context.record = {}
    79	
    80	    // Call the storage helper
    81	    await helpers.dataDelete({
    82	      scopeName,
    83	      context
    84	    })
    85	
    86	    await runHooks('afterDataCallDelete')
    87	    await runHooks('afterDataCall')
    88	
    89	    // No return record for DELETE (204 No Content)
    90	
    91	    await runHooks('finish')
    92	    await runHooks('finishDelete')
    93	
    94	    // Commit transaction if we created it
    95	    if (context.shouldCommit) {
    96	      await context.transaction.commit()
    97	      await runHooks('afterCommit')
    98	    }
    99	
   100	    // DELETE typically returns void/undefined (204 No Content)
   101	  } catch (error) {
   102	    await handleWriteMethodError(error, context, 'DELETE', scopeName, log, runHooks)
   103	  }
   104	}
