import { queryParams, type RouteQueryOptions, type RouteDefinition, type RouteFormDefinition, applyUrlDefaults } from './../../../wayfinder'
/**
* @see \App\Http\Controllers\Admin\ConversationTagAssignmentController::attach
* @see app/Http/Controllers/Admin/ConversationTagAssignmentController.php:18
* @route '/app/conversations/{conversation}/tags/{tag}'
*/
export const attach = (args: { conversation: string | number | { id: string | number }, tag: string | number | { id: string | number } } | [conversation: string | number | { id: string | number }, tag: string | number | { id: string | number } ], options?: RouteQueryOptions): RouteDefinition<'post'> => ({
    url: attach.url(args, options),
    method: 'post',
})

attach.definition = {
    methods: ["post"],
    url: '/app/conversations/{conversation}/tags/{tag}',
} satisfies RouteDefinition<["post"]>

/**
* @see \App\Http\Controllers\Admin\ConversationTagAssignmentController::attach
* @see app/Http/Controllers/Admin/ConversationTagAssignmentController.php:18
* @route '/app/conversations/{conversation}/tags/{tag}'
*/
attach.url = (args: { conversation: string | number | { id: string | number }, tag: string | number | { id: string | number } } | [conversation: string | number | { id: string | number }, tag: string | number | { id: string | number } ], options?: RouteQueryOptions) => {
    if (Array.isArray(args)) {
        args = {
            conversation: args[0],
            tag: args[1],
        }
    }

    args = applyUrlDefaults(args)

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

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

/**
* @see \App\Http\Controllers\Admin\ConversationTagAssignmentController::attach
* @see app/Http/Controllers/Admin/ConversationTagAssignmentController.php:18
* @route '/app/conversations/{conversation}/tags/{tag}'
*/
attach.post = (args: { conversation: string | number | { id: string | number }, tag: string | number | { id: string | number } } | [conversation: string | number | { id: string | number }, tag: string | number | { id: string | number } ], options?: RouteQueryOptions): RouteDefinition<'post'> => ({
    url: attach.url(args, options),
    method: 'post',
})

/**
* @see \App\Http\Controllers\Admin\ConversationTagAssignmentController::attach
* @see app/Http/Controllers/Admin/ConversationTagAssignmentController.php:18
* @route '/app/conversations/{conversation}/tags/{tag}'
*/
const attachForm = (args: { conversation: string | number | { id: string | number }, tag: string | number | { id: string | number } } | [conversation: string | number | { id: string | number }, tag: string | number | { id: string | number } ], options?: RouteQueryOptions): RouteFormDefinition<'post'> => ({
    action: attach.url(args, options),
    method: 'post',
})

/**
* @see \App\Http\Controllers\Admin\ConversationTagAssignmentController::attach
* @see app/Http/Controllers/Admin/ConversationTagAssignmentController.php:18
* @route '/app/conversations/{conversation}/tags/{tag}'
*/
attachForm.post = (args: { conversation: string | number | { id: string | number }, tag: string | number | { id: string | number } } | [conversation: string | number | { id: string | number }, tag: string | number | { id: string | number } ], options?: RouteQueryOptions): RouteFormDefinition<'post'> => ({
    action: attach.url(args, options),
    method: 'post',
})

attach.form = attachForm

/**
* @see \App\Http\Controllers\Admin\ConversationTagAssignmentController::detach
* @see app/Http/Controllers/Admin/ConversationTagAssignmentController.php:34
* @route '/app/conversations/{conversation}/tags/{tag}'
*/
export const detach = (args: { conversation: string | number | { id: string | number }, tag: string | number | { id: string | number } } | [conversation: string | number | { id: string | number }, tag: string | number | { id: string | number } ], options?: RouteQueryOptions): RouteDefinition<'delete'> => ({
    url: detach.url(args, options),
    method: 'delete',
})

detach.definition = {
    methods: ["delete"],
    url: '/app/conversations/{conversation}/tags/{tag}',
} satisfies RouteDefinition<["delete"]>

/**
* @see \App\Http\Controllers\Admin\ConversationTagAssignmentController::detach
* @see app/Http/Controllers/Admin/ConversationTagAssignmentController.php:34
* @route '/app/conversations/{conversation}/tags/{tag}'
*/
detach.url = (args: { conversation: string | number | { id: string | number }, tag: string | number | { id: string | number } } | [conversation: string | number | { id: string | number }, tag: string | number | { id: string | number } ], options?: RouteQueryOptions) => {
    if (Array.isArray(args)) {
        args = {
            conversation: args[0],
            tag: args[1],
        }
    }

    args = applyUrlDefaults(args)

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

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

/**
* @see \App\Http\Controllers\Admin\ConversationTagAssignmentController::detach
* @see app/Http/Controllers/Admin/ConversationTagAssignmentController.php:34
* @route '/app/conversations/{conversation}/tags/{tag}'
*/
detach.delete = (args: { conversation: string | number | { id: string | number }, tag: string | number | { id: string | number } } | [conversation: string | number | { id: string | number }, tag: string | number | { id: string | number } ], options?: RouteQueryOptions): RouteDefinition<'delete'> => ({
    url: detach.url(args, options),
    method: 'delete',
})

/**
* @see \App\Http\Controllers\Admin\ConversationTagAssignmentController::detach
* @see app/Http/Controllers/Admin/ConversationTagAssignmentController.php:34
* @route '/app/conversations/{conversation}/tags/{tag}'
*/
const detachForm = (args: { conversation: string | number | { id: string | number }, tag: string | number | { id: string | number } } | [conversation: string | number | { id: string | number }, tag: string | number | { id: string | 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\ConversationTagAssignmentController::detach
* @see app/Http/Controllers/Admin/ConversationTagAssignmentController.php:34
* @route '/app/conversations/{conversation}/tags/{tag}'
*/
detachForm.delete = (args: { conversation: string | number | { id: string | number }, tag: string | number | { id: string | number } } | [conversation: string | number | { id: string | number }, tag: string | number | { id: string | 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 tags = {
    attach: Object.assign(attach, attach),
    detach: Object.assign(detach, detach),
}

export default tags