import { queryParams, type RouteQueryOptions, type RouteDefinition, type RouteFormDefinition, applyUrlDefaults } from './../../../wayfinder'
/**
* @see \App\Http\Controllers\Admin\StandManagementController::store
* @see app/Http/Controllers/Admin/StandManagementController.php:19
* @route '/admin/locations/{location}/stands'
*/
export const store = (args: { location: number | { id: number } } | [location: number | { id: number } ] | number | { id: number }, options?: RouteQueryOptions): RouteDefinition<'post'> => ({
    url: store.url(args, options),
    method: 'post',
})

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

/**
* @see \App\Http\Controllers\Admin\StandManagementController::store
* @see app/Http/Controllers/Admin/StandManagementController.php:19
* @route '/admin/locations/{location}/stands'
*/
store.url = (args: { location: number | { id: number } } | [location: number | { id: number } ] | number | { id: number }, options?: RouteQueryOptions) => {
    if (typeof args === 'string' || typeof args === 'number') {
        args = { location: args }
    }

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

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

    args = applyUrlDefaults(args)

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

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

/**
* @see \App\Http\Controllers\Admin\StandManagementController::store
* @see app/Http/Controllers/Admin/StandManagementController.php:19
* @route '/admin/locations/{location}/stands'
*/
store.post = (args: { location: number | { id: number } } | [location: number | { id: number } ] | number | { id: number }, options?: RouteQueryOptions): RouteDefinition<'post'> => ({
    url: store.url(args, options),
    method: 'post',
})

/**
* @see \App\Http\Controllers\Admin\StandManagementController::store
* @see app/Http/Controllers/Admin/StandManagementController.php:19
* @route '/admin/locations/{location}/stands'
*/
const storeForm = (args: { location: number | { id: number } } | [location: number | { id: number } ] | number | { id: number }, options?: RouteQueryOptions): RouteFormDefinition<'post'> => ({
    action: store.url(args, options),
    method: 'post',
})

/**
* @see \App\Http\Controllers\Admin\StandManagementController::store
* @see app/Http/Controllers/Admin/StandManagementController.php:19
* @route '/admin/locations/{location}/stands'
*/
storeForm.post = (args: { location: number | { id: number } } | [location: number | { id: number } ] | number | { id: number }, options?: RouteQueryOptions): RouteFormDefinition<'post'> => ({
    action: store.url(args, options),
    method: 'post',
})

store.form = storeForm

/**
* @see \App\Http\Controllers\Admin\StandManagementController::update
* @see app/Http/Controllers/Admin/StandManagementController.php:43
* @route '/admin/stands/{stand}'
*/
export const update = (args: { stand: number | { id: number } } | [stand: number | { id: number } ] | number | { id: number }, options?: RouteQueryOptions): RouteDefinition<'patch'> => ({
    url: update.url(args, options),
    method: 'patch',
})

update.definition = {
    methods: ["patch"],
    url: '/admin/stands/{stand}',
} satisfies RouteDefinition<["patch"]>

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

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

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

    args = applyUrlDefaults(args)

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

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

/**
* @see \App\Http\Controllers\Admin\StandManagementController::update
* @see app/Http/Controllers/Admin/StandManagementController.php:43
* @route '/admin/stands/{stand}'
*/
update.patch = (args: { stand: number | { id: number } } | [stand: number | { id: number } ] | number | { id: number }, options?: RouteQueryOptions): RouteDefinition<'patch'> => ({
    url: update.url(args, options),
    method: 'patch',
})

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

/**
* @see \App\Http\Controllers\Admin\StandManagementController::update
* @see app/Http/Controllers/Admin/StandManagementController.php:43
* @route '/admin/stands/{stand}'
*/
updateForm.patch = (args: { stand: number | { id: number } } | [stand: number | { id: number } ] | number | { id: number }, options?: RouteQueryOptions): RouteFormDefinition<'post'> => ({
    action: update.url(args, {
        [options?.mergeQuery ? 'mergeQuery' : 'query']: {
            _method: 'PATCH',
            ...(options?.query ?? options?.mergeQuery ?? {}),
        }
    }),
    method: 'post',
})

update.form = updateForm

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

export default stands