import { queryParams, type RouteQueryOptions, type RouteDefinition, type RouteFormDefinition, applyUrlDefaults } from './../../../wayfinder'
/**
* @see \App\Http\Controllers\CreditNotesController::store
* @see app/Http/Controllers/CreditNotesController.php:536
* @route '/credit-notes/{creditNote}/payments'
*/
export const store = (args: { creditNote: string | number | { id: string | number } } | [creditNote: string | number | { id: string | number } ] | string | number | { id: string | number }, options?: RouteQueryOptions): RouteDefinition<'post'> => ({
    url: store.url(args, options),
    method: 'post',
})

store.definition = {
    methods: ["post"],
    url: '/credit-notes/{creditNote}/payments',
} satisfies RouteDefinition<["post"]>

/**
* @see \App\Http\Controllers\CreditNotesController::store
* @see app/Http/Controllers/CreditNotesController.php:536
* @route '/credit-notes/{creditNote}/payments'
*/
store.url = (args: { creditNote: string | number | { id: string | number } } | [creditNote: string | number | { id: string | number } ] | string | number | { id: string | number }, options?: RouteQueryOptions) => {
    if (typeof args === 'string' || typeof args === 'number') {
        args = { creditNote: args }
    }

    if (typeof args === 'object' && !Array.isArray(args) && 'id' in args) {
        args = { creditNote: args.id }
    }

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

    args = applyUrlDefaults(args)

    const parsedArgs = {
        creditNote: typeof args.creditNote === 'object'
        ? args.creditNote.id
        : args.creditNote,
    }

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

/**
* @see \App\Http\Controllers\CreditNotesController::store
* @see app/Http/Controllers/CreditNotesController.php:536
* @route '/credit-notes/{creditNote}/payments'
*/
store.post = (args: { creditNote: string | number | { id: string | number } } | [creditNote: string | number | { id: string | number } ] | string | number | { id: string | number }, options?: RouteQueryOptions): RouteDefinition<'post'> => ({
    url: store.url(args, options),
    method: 'post',
})

/**
* @see \App\Http\Controllers\CreditNotesController::store
* @see app/Http/Controllers/CreditNotesController.php:536
* @route '/credit-notes/{creditNote}/payments'
*/
const storeForm = (args: { creditNote: string | number | { id: string | number } } | [creditNote: string | number | { id: string | number } ] | string | number | { id: string | number }, options?: RouteQueryOptions): RouteFormDefinition<'post'> => ({
    action: store.url(args, options),
    method: 'post',
})

/**
* @see \App\Http\Controllers\CreditNotesController::store
* @see app/Http/Controllers/CreditNotesController.php:536
* @route '/credit-notes/{creditNote}/payments'
*/
storeForm.post = (args: { creditNote: string | number | { id: string | number } } | [creditNote: string | number | { id: string | number } ] | string | number | { id: string | number }, options?: RouteQueryOptions): RouteFormDefinition<'post'> => ({
    action: store.url(args, options),
    method: 'post',
})

store.form = storeForm

/**
* @see \App\Http\Controllers\CreditNotesController::destroy
* @see app/Http/Controllers/CreditNotesController.php:593
* @route '/credit-notes/{creditNote}/payments/{payment}'
*/
export const destroy = (args: { creditNote: string | number | { id: string | number }, payment: string | number | { id: string | number } } | [creditNote: string | number | { id: string | number }, payment: string | number | { id: string | number } ], options?: RouteQueryOptions): RouteDefinition<'delete'> => ({
    url: destroy.url(args, options),
    method: 'delete',
})

destroy.definition = {
    methods: ["delete"],
    url: '/credit-notes/{creditNote}/payments/{payment}',
} satisfies RouteDefinition<["delete"]>

/**
* @see \App\Http\Controllers\CreditNotesController::destroy
* @see app/Http/Controllers/CreditNotesController.php:593
* @route '/credit-notes/{creditNote}/payments/{payment}'
*/
destroy.url = (args: { creditNote: string | number | { id: string | number }, payment: string | number | { id: string | number } } | [creditNote: string | number | { id: string | number }, payment: string | number | { id: string | number } ], options?: RouteQueryOptions) => {
    if (Array.isArray(args)) {
        args = {
            creditNote: args[0],
            payment: args[1],
        }
    }

    args = applyUrlDefaults(args)

    const parsedArgs = {
        creditNote: typeof args.creditNote === 'object'
        ? args.creditNote.id
        : args.creditNote,
        payment: typeof args.payment === 'object'
        ? args.payment.id
        : args.payment,
    }

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

/**
* @see \App\Http\Controllers\CreditNotesController::destroy
* @see app/Http/Controllers/CreditNotesController.php:593
* @route '/credit-notes/{creditNote}/payments/{payment}'
*/
destroy.delete = (args: { creditNote: string | number | { id: string | number }, payment: string | number | { id: string | number } } | [creditNote: string | number | { id: string | number }, payment: string | number | { id: string | number } ], options?: RouteQueryOptions): RouteDefinition<'delete'> => ({
    url: destroy.url(args, options),
    method: 'delete',
})

/**
* @see \App\Http\Controllers\CreditNotesController::destroy
* @see app/Http/Controllers/CreditNotesController.php:593
* @route '/credit-notes/{creditNote}/payments/{payment}'
*/
const destroyForm = (args: { creditNote: string | number | { id: string | number }, payment: string | number | { id: string | number } } | [creditNote: string | number | { id: string | number }, payment: string | number | { id: 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\CreditNotesController::destroy
* @see app/Http/Controllers/CreditNotesController.php:593
* @route '/credit-notes/{creditNote}/payments/{payment}'
*/
destroyForm.delete = (args: { creditNote: string | number | { id: string | number }, payment: string | number | { id: string | number } } | [creditNote: string | number | { id: string | number }, payment: string | number | { id: 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 payments = {
    store: Object.assign(store, store),
    destroy: Object.assign(destroy, destroy),
}

export default payments