import { queryParams, type RouteQueryOptions, type RouteDefinition, type RouteFormDefinition, applyUrlDefaults } from './../../../../wayfinder'
/**
* @see \App\Http\Controllers\Admin\AdminUserDirectoryController::attach
* @see app/Http/Controllers/Admin/AdminUserDirectoryController.php:225
* @route '/admin/usuarios/{user}/referidos-manuales'
*/
export const attach = (args: { user: number | { id: number } } | [user: number | { id: number } ] | number | { id: number }, options?: RouteQueryOptions): RouteDefinition<'post'> => ({
    url: attach.url(args, options),
    method: 'post',
})

attach.definition = {
    methods: ["post"],
    url: '/admin/usuarios/{user}/referidos-manuales',
} satisfies RouteDefinition<["post"]>

/**
* @see \App\Http\Controllers\Admin\AdminUserDirectoryController::attach
* @see app/Http/Controllers/Admin/AdminUserDirectoryController.php:225
* @route '/admin/usuarios/{user}/referidos-manuales'
*/
attach.url = (args: { user: number | { id: number } } | [user: number | { id: number } ] | number | { id: number }, options?: RouteQueryOptions) => {
    if (typeof args === 'string' || typeof args === 'number') {
        args = { user: args }
    }

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

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

    args = applyUrlDefaults(args)

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

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

/**
* @see \App\Http\Controllers\Admin\AdminUserDirectoryController::attach
* @see app/Http/Controllers/Admin/AdminUserDirectoryController.php:225
* @route '/admin/usuarios/{user}/referidos-manuales'
*/
attach.post = (args: { user: number | { id: number } } | [user: number | { id: number } ] | number | { id: number }, options?: RouteQueryOptions): RouteDefinition<'post'> => ({
    url: attach.url(args, options),
    method: 'post',
})

/**
* @see \App\Http\Controllers\Admin\AdminUserDirectoryController::attach
* @see app/Http/Controllers/Admin/AdminUserDirectoryController.php:225
* @route '/admin/usuarios/{user}/referidos-manuales'
*/
const attachForm = (args: { user: number | { id: number } } | [user: number | { id: number } ] | number | { id: number }, options?: RouteQueryOptions): RouteFormDefinition<'post'> => ({
    action: attach.url(args, options),
    method: 'post',
})

/**
* @see \App\Http\Controllers\Admin\AdminUserDirectoryController::attach
* @see app/Http/Controllers/Admin/AdminUserDirectoryController.php:225
* @route '/admin/usuarios/{user}/referidos-manuales'
*/
attachForm.post = (args: { user: number | { id: number } } | [user: number | { id: number } ] | number | { id: number }, options?: RouteQueryOptions): RouteFormDefinition<'post'> => ({
    action: attach.url(args, options),
    method: 'post',
})

attach.form = attachForm

/**
* @see \App\Http\Controllers\Admin\AdminUserDirectoryController::detach
* @see app/Http/Controllers/Admin/AdminUserDirectoryController.php:269
* @route '/admin/usuarios/{user}/referidos-manuales/{referred}'
*/
export const detach = (args: { user: number | { id: number }, referred: number | { id: number } } | [user: number | { id: number }, referred: number | { id: number } ], options?: RouteQueryOptions): RouteDefinition<'delete'> => ({
    url: detach.url(args, options),
    method: 'delete',
})

detach.definition = {
    methods: ["delete"],
    url: '/admin/usuarios/{user}/referidos-manuales/{referred}',
} satisfies RouteDefinition<["delete"]>

/**
* @see \App\Http\Controllers\Admin\AdminUserDirectoryController::detach
* @see app/Http/Controllers/Admin/AdminUserDirectoryController.php:269
* @route '/admin/usuarios/{user}/referidos-manuales/{referred}'
*/
detach.url = (args: { user: number | { id: number }, referred: number | { id: number } } | [user: number | { id: number }, referred: number | { id: number } ], options?: RouteQueryOptions) => {
    if (Array.isArray(args)) {
        args = {
            user: args[0],
            referred: args[1],
        }
    }

    args = applyUrlDefaults(args)

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

    return detach.definition.url
            .replace('{user}', parsedArgs.user.toString())
            .replace('{referred}', parsedArgs.referred.toString())
            .replace(/\/+$/, '') + queryParams(options)
}

/**
* @see \App\Http\Controllers\Admin\AdminUserDirectoryController::detach
* @see app/Http/Controllers/Admin/AdminUserDirectoryController.php:269
* @route '/admin/usuarios/{user}/referidos-manuales/{referred}'
*/
detach.delete = (args: { user: number | { id: number }, referred: number | { id: number } } | [user: number | { id: number }, referred: number | { id: number } ], options?: RouteQueryOptions): RouteDefinition<'delete'> => ({
    url: detach.url(args, options),
    method: 'delete',
})

/**
* @see \App\Http\Controllers\Admin\AdminUserDirectoryController::detach
* @see app/Http/Controllers/Admin/AdminUserDirectoryController.php:269
* @route '/admin/usuarios/{user}/referidos-manuales/{referred}'
*/
const detachForm = (args: { user: number | { id: number }, referred: number | { id: number } } | [user: number | { id: number }, referred: number | { id: number } ], options?: RouteQueryOptions): RouteFormDefinition<'post'> => ({
    action: detach.url(args, {
        [options?.mergeQuery ? 'mergeQuery' : 'query']: {
            _method: 'DELETE',
            ...(options?.query ?? options?.mergeQuery ?? {}),
        }
    }),
    method: 'post',
})

/**
* @see \App\Http\Controllers\Admin\AdminUserDirectoryController::detach
* @see app/Http/Controllers/Admin/AdminUserDirectoryController.php:269
* @route '/admin/usuarios/{user}/referidos-manuales/{referred}'
*/
detachForm.delete = (args: { user: number | { id: number }, referred: number | { id: number } } | [user: number | { id: number }, referred: number | { id: number } ], options?: RouteQueryOptions): RouteFormDefinition<'post'> => ({
    action: detach.url(args, {
        [options?.mergeQuery ? 'mergeQuery' : 'query']: {
            _method: 'DELETE',
            ...(options?.query ?? options?.mergeQuery ?? {}),
        }
    }),
    method: 'post',
})

detach.form = detachForm

const manualDirectReferrals = {
    attach: Object.assign(attach, attach),
    detach: Object.assign(detach, detach),
}

export default manualDirectReferrals