import { queryParams, type RouteQueryOptions, type RouteDefinition, type RouteFormDefinition, applyUrlDefaults } from './../../../wayfinder'
/**
* @see \App\Http\Controllers\InvoicesController::store
* @see app/Http/Controllers/InvoicesController.php:1282
* @route '/invoices/recurring'
*/
export const store = (options?: RouteQueryOptions): RouteDefinition<'post'> => ({
    url: store.url(options),
    method: 'post',
})

store.definition = {
    methods: ["post"],
    url: '/invoices/recurring',
} satisfies RouteDefinition<["post"]>

/**
* @see \App\Http\Controllers\InvoicesController::store
* @see app/Http/Controllers/InvoicesController.php:1282
* @route '/invoices/recurring'
*/
store.url = (options?: RouteQueryOptions) => {
    return store.definition.url + queryParams(options)
}

/**
* @see \App\Http\Controllers\InvoicesController::store
* @see app/Http/Controllers/InvoicesController.php:1282
* @route '/invoices/recurring'
*/
store.post = (options?: RouteQueryOptions): RouteDefinition<'post'> => ({
    url: store.url(options),
    method: 'post',
})

/**
* @see \App\Http\Controllers\InvoicesController::store
* @see app/Http/Controllers/InvoicesController.php:1282
* @route '/invoices/recurring'
*/
const storeForm = (options?: RouteQueryOptions): RouteFormDefinition<'post'> => ({
    action: store.url(options),
    method: 'post',
})

/**
* @see \App\Http\Controllers\InvoicesController::store
* @see app/Http/Controllers/InvoicesController.php:1282
* @route '/invoices/recurring'
*/
storeForm.post = (options?: RouteQueryOptions): RouteFormDefinition<'post'> => ({
    action: store.url(options),
    method: 'post',
})

store.form = storeForm

/**
* @see \App\Http\Controllers\InvoicesController::destroy
* @see app/Http/Controllers/InvoicesController.php:1313
* @route '/invoices/recurring/{recurringDocument}'
*/
export const destroy = (args: { recurringDocument: string | number } | [recurringDocument: string | number ] | string | number, options?: RouteQueryOptions): RouteDefinition<'delete'> => ({
    url: destroy.url(args, options),
    method: 'delete',
})

destroy.definition = {
    methods: ["delete"],
    url: '/invoices/recurring/{recurringDocument}',
} satisfies RouteDefinition<["delete"]>

/**
* @see \App\Http\Controllers\InvoicesController::destroy
* @see app/Http/Controllers/InvoicesController.php:1313
* @route '/invoices/recurring/{recurringDocument}'
*/
destroy.url = (args: { recurringDocument: string | number } | [recurringDocument: string | number ] | string | number, options?: RouteQueryOptions) => {
    if (typeof args === 'string' || typeof args === 'number') {
        args = { recurringDocument: args }
    }

    if (Array.isArray(args)) {
        args = {
            recurringDocument: args[0],
        }
    }

    args = applyUrlDefaults(args)

    const parsedArgs = {
        recurringDocument: args.recurringDocument,
    }

    return destroy.definition.url
            .replace('{recurringDocument}', parsedArgs.recurringDocument.toString())
            .replace(/\/+$/, '') + queryParams(options)
}

/**
* @see \App\Http\Controllers\InvoicesController::destroy
* @see app/Http/Controllers/InvoicesController.php:1313
* @route '/invoices/recurring/{recurringDocument}'
*/
destroy.delete = (args: { recurringDocument: string | number } | [recurringDocument: string | number ] | string | number, options?: RouteQueryOptions): RouteDefinition<'delete'> => ({
    url: destroy.url(args, options),
    method: 'delete',
})

/**
* @see \App\Http\Controllers\InvoicesController::destroy
* @see app/Http/Controllers/InvoicesController.php:1313
* @route '/invoices/recurring/{recurringDocument}'
*/
const destroyForm = (args: { recurringDocument: string | number } | [recurringDocument: string | number ] | string | number, options?: RouteQueryOptions): RouteFormDefinition<'post'> => ({
    action: destroy.url(args, {
        [options?.mergeQuery ? 'mergeQuery' : 'query']: {
            _method: 'DELETE',
            ...(options?.query ?? options?.mergeQuery ?? {}),
        }
    }),
    method: 'post',
})

/**
* @see \App\Http\Controllers\InvoicesController::destroy
* @see app/Http/Controllers/InvoicesController.php:1313
* @route '/invoices/recurring/{recurringDocument}'
*/
destroyForm.delete = (args: { recurringDocument: string | number } | [recurringDocument: string | number ] | string | number, options?: RouteQueryOptions): RouteFormDefinition<'post'> => ({
    action: destroy.url(args, {
        [options?.mergeQuery ? 'mergeQuery' : 'query']: {
            _method: 'DELETE',
            ...(options?.query ?? options?.mergeQuery ?? {}),
        }
    }),
    method: 'post',
})

destroy.form = destroyForm

const recurring = {
    store: Object.assign(store, store),
    destroy: Object.assign(destroy, destroy),
}

export default recurring