import type { FixRequest } from '../../shared/api/types/fixes';
import type { BrokenLinkChoice } from './brokenLinkOptions';
import type { FixAllMode } from './fixAllTexts';

export type FixAllRequest = FixRequest & { status: FixAllMode };

export function fixAllRequestOf(
	mode: FixAllMode,
	choice: BrokenLinkChoice,
	typedAddress: string
): FixAllRequest {
	if ( mode === 'moved' ) {
		return { action: 'update', status: mode };
	}

	if ( choice === 'replace' ) {
		return { action: choice, status: mode, new_url: typedAddress.trim() };
	}

	return { action: choice, status: mode };
}
