def METHOD_NAME(
    self,
    dockerfile: DockerfileParser,
    stage: DockerfileStage,
    idx: int,
    start_lines: List[str],
    end_lines: List[str],
    custom_image_index: List[int]
) -> None:
    """Add the specified lines at the start and end of the specified stage in the Dockerfile."""
    from_structure, after_from_structure, end_structure, stage_user = stage
    self.log.debug("updating stage starting line %d, ending at %d",
                   from_structure['startline'], end_structure['endline'])
    add_start_lines = []
    add_end_lines = []
    base_image_stage = False
    parent_image_id = from_structure['value'].split(' ', 1)[0]
    if parent_image_id == SCRATCH_FROM:
        if idx not in custom_image_index:
            return
        # is scratch stage but for baseimage
        else:
            base_image_stage = True
    inherited_user = ''
    if not base_image_stage:
        # inspect any platform, the parent user should be the same for all platforms
        inspect = self.workflow.imageutil.get_inspect_for_image(parent_image_id)
        inherited_user = inspect.get(INSPECT_CONFIG, {}).get('User', '')
    if inherited_user:
        add_start_lines.append('USER root')
    add_start_lines.extend(start_lines)
    if inherited_user:
        add_start_lines.append('USER {}'.format(inherited_user))
    final_user_line = "USER " + inherited_user if inherited_user else None
    if stage_user:
        final_user_line = stage_user
    if final_user_line:
        add_end_lines.append('USER root')
    add_end_lines.extend(end_lines)
    if final_user_line:
        add_end_lines.append(final_user_line)
    self.log.debug("append after: %r", add_end_lines)
    self.log.debug("insert before: %r", add_start_lines)
    dockerfile.add_lines_at(end_structure, *add_end_lines, after=True)
    if base_image_stage:
        dockerfile.add_lines_at(after_from_structure, *add_start_lines, after=True)
    else:
        dockerfile.add_lines_at(from_structure, *add_start_lines, after=True)