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

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

/**
* @see \App\Http\Controllers\Admin\ReservationController::store
* @see app/Http/Controllers/Admin/ReservationController.php:18
* @route '/admin/apartados'
*/
store.url = (options?: RouteQueryOptions) => {
    return store.definition.url + queryParams(options)
}

/**
* @see \App\Http\Controllers\Admin\ReservationController::store
* @see app/Http/Controllers/Admin/ReservationController.php:18
* @route '/admin/apartados'
*/
store.post = (options?: RouteQueryOptions): RouteDefinition<'post'> => ({
    url: store.url(options),
    method: 'post',
})

/**
* @see \App\Http\Controllers\Admin\ReservationController::store
* @see app/Http/Controllers/Admin/ReservationController.php:18
* @route '/admin/apartados'
*/
const storeForm = (options?: RouteQueryOptions): RouteFormDefinition<'post'> => ({
    action: store.url(options),
    method: 'post',
})

/**
* @see \App\Http\Controllers\Admin\ReservationController::store
* @see app/Http/Controllers/Admin/ReservationController.php:18
* @route '/admin/apartados'
*/
storeForm.post = (options?: RouteQueryOptions): RouteFormDefinition<'post'> => ({
    action: store.url(options),
    method: 'post',
})

store.form = storeForm

/**
* @see \App\Http\Controllers\Admin\ReservationController::update
* @see app/Http/Controllers/Admin/ReservationController.php:52
* @route '/admin/apartados/{reservation}'
*/
export const update = (args: { reservation: number | { id: number } } | [reservation: number | { id: number } ] | number | { id: number }, options?: RouteQueryOptions): RouteDefinition<'put'> => ({
    url: update.url(args, options),
    method: 'put',
})

update.definition = {
    methods: ["put"],
    url: '/admin/apartados/{reservation}',
} satisfies RouteDefinition<["put"]>

/**
* @see \App\Http\Controllers\Admin\ReservationController::update
* @see app/Http/Controllers/Admin/ReservationController.php:52
* @route '/admin/apartados/{reservation}'
*/
update.url = (args: { reservation: number | { id: number } } | [reservation: number | { id: number } ] | number | { id: number }, options?: RouteQueryOptions) => {
    if (typeof args === 'string' || typeof args === 'number') {
        args = { reservation: args }
    }

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

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

    args = applyUrlDefaults(args)

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

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

/**
* @see \App\Http\Controllers\Admin\ReservationController::update
* @see app/Http/Controllers/Admin/ReservationController.php:52
* @route '/admin/apartados/{reservation}'
*/
update.put = (args: { reservation: number | { id: number } } | [reservation: number | { id: number } ] | number | { id: number }, options?: RouteQueryOptions): RouteDefinition<'put'> => ({
    url: update.url(args, options),
    method: 'put',
})

/**
* @see \App\Http\Controllers\Admin\ReservationController::update
* @see app/Http/Controllers/Admin/ReservationController.php:52
* @route '/admin/apartados/{reservation}'
*/
const updateForm = (args: { reservation: number | { id: number } } | [reservation: number | { id: number } ] | number | { id: number }, options?: RouteQueryOptions): RouteFormDefinition<'post'> => ({
    action: update.url(args, {
        [options?.mergeQuery ? 'mergeQuery' : 'query']: {
            _method: 'PUT',
            ...(options?.query ?? options?.mergeQuery ?? {}),
        }
    }),
    method: 'post',
})

/**
* @see \App\Http\Controllers\Admin\ReservationController::update
* @see app/Http/Controllers/Admin/ReservationController.php:52
* @route '/admin/apartados/{reservation}'
*/
updateForm.put = (args: { reservation: number | { id: number } } | [reservation: number | { id: number } ] | number | { id: number }, options?: RouteQueryOptions): RouteFormDefinition<'post'> => ({
    action: update.url(args, {
        [options?.mergeQuery ? 'mergeQuery' : 'query']: {
            _method: 'PUT',
            ...(options?.query ?? options?.mergeQuery ?? {}),
        }
    }),
    method: 'post',
})

update.form = updateForm

const reservations = {
    store: Object.assign(store, store),
    update: Object.assign(update, update),
}

export default reservations