import { queryParams, type RouteQueryOptions, type RouteDefinition, type RouteFormDefinition, applyUrlDefaults } from './../../wayfinder'
/**
* @see \App\Http\Controllers\SimulationCostAllocationController::update
* @see app/Http/Controllers/SimulationCostAllocationController.php:20
* @route '/simulations/{simulation}/costs/{type}/{cost}/allocations'
*/
export const update = (args: { simulation: number | { id: number }, type: string | number, cost: string | number } | [simulation: number | { id: number }, type: string | number, cost: string | number ], options?: RouteQueryOptions): RouteDefinition<'put'> => ({
    url: update.url(args, options),
    method: 'put',
})

update.definition = {
    methods: ["put"],
    url: '/simulations/{simulation}/costs/{type}/{cost}/allocations',
} satisfies RouteDefinition<["put"]>

/**
* @see \App\Http\Controllers\SimulationCostAllocationController::update
* @see app/Http/Controllers/SimulationCostAllocationController.php:20
* @route '/simulations/{simulation}/costs/{type}/{cost}/allocations'
*/
update.url = (args: { simulation: number | { id: number }, type: string | number, cost: string | number } | [simulation: number | { id: number }, type: string | number, cost: string | number ], options?: RouteQueryOptions) => {
    if (Array.isArray(args)) {
        args = {
            simulation: args[0],
            type: args[1],
            cost: args[2],
        }
    }

    args = applyUrlDefaults(args)

    const parsedArgs = {
        simulation: typeof args.simulation === 'object'
        ? args.simulation.id
        : args.simulation,
        type: args.type,
        cost: args.cost,
    }

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

/**
* @see \App\Http\Controllers\SimulationCostAllocationController::update
* @see app/Http/Controllers/SimulationCostAllocationController.php:20
* @route '/simulations/{simulation}/costs/{type}/{cost}/allocations'
*/
update.put = (args: { simulation: number | { id: number }, type: string | number, cost: string | number } | [simulation: number | { id: number }, type: string | number, cost: string | number ], options?: RouteQueryOptions): RouteDefinition<'put'> => ({
    url: update.url(args, options),
    method: 'put',
})

/**
* @see \App\Http\Controllers\SimulationCostAllocationController::update
* @see app/Http/Controllers/SimulationCostAllocationController.php:20
* @route '/simulations/{simulation}/costs/{type}/{cost}/allocations'
*/
const updateForm = (args: { simulation: number | { id: number }, type: string | number, cost: string | number } | [simulation: number | { id: number }, type: string | number, cost: string | 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\SimulationCostAllocationController::update
* @see app/Http/Controllers/SimulationCostAllocationController.php:20
* @route '/simulations/{simulation}/costs/{type}/{cost}/allocations'
*/
updateForm.put = (args: { simulation: number | { id: number }, type: string | number, cost: string | number } | [simulation: number | { id: number }, type: string | number, cost: string | number ], options?: RouteQueryOptions): RouteFormDefinition<'post'> => ({
    action: update.url(args, {
        [options?.mergeQuery ? 'mergeQuery' : 'query']: {
            _method: 'PUT',
            ...(options?.query ?? options?.mergeQuery ?? {}),
        }
    }),
    method: 'post',
})

update.form = updateForm

/**
* @see \App\Http\Controllers\SimulationCostAllocationController::destroy
* @see app/Http/Controllers/SimulationCostAllocationController.php:78
* @route '/simulations/{simulation}/costs/{type}/{cost}/allocations/{project}'
*/
export const destroy = (args: { simulation: number | { id: number }, type: string | number, cost: string | number, project: string | number } | [simulation: number | { id: number }, type: string | number, cost: string | number, project: string | number ], options?: RouteQueryOptions): RouteDefinition<'delete'> => ({
    url: destroy.url(args, options),
    method: 'delete',
})

destroy.definition = {
    methods: ["delete"],
    url: '/simulations/{simulation}/costs/{type}/{cost}/allocations/{project}',
} satisfies RouteDefinition<["delete"]>

/**
* @see \App\Http\Controllers\SimulationCostAllocationController::destroy
* @see app/Http/Controllers/SimulationCostAllocationController.php:78
* @route '/simulations/{simulation}/costs/{type}/{cost}/allocations/{project}'
*/
destroy.url = (args: { simulation: number | { id: number }, type: string | number, cost: string | number, project: string | number } | [simulation: number | { id: number }, type: string | number, cost: string | number, project: string | number ], options?: RouteQueryOptions) => {
    if (Array.isArray(args)) {
        args = {
            simulation: args[0],
            type: args[1],
            cost: args[2],
            project: args[3],
        }
    }

    args = applyUrlDefaults(args)

    const parsedArgs = {
        simulation: typeof args.simulation === 'object'
        ? args.simulation.id
        : args.simulation,
        type: args.type,
        cost: args.cost,
        project: args.project,
    }

    return destroy.definition.url
            .replace('{simulation}', parsedArgs.simulation.toString())
            .replace('{type}', parsedArgs.type.toString())
            .replace('{cost}', parsedArgs.cost.toString())
            .replace('{project}', parsedArgs.project.toString())
            .replace(/\/+$/, '') + queryParams(options)
}

/**
* @see \App\Http\Controllers\SimulationCostAllocationController::destroy
* @see app/Http/Controllers/SimulationCostAllocationController.php:78
* @route '/simulations/{simulation}/costs/{type}/{cost}/allocations/{project}'
*/
destroy.delete = (args: { simulation: number | { id: number }, type: string | number, cost: string | number, project: string | number } | [simulation: number | { id: number }, type: string | number, cost: string | number, project: string | number ], options?: RouteQueryOptions): RouteDefinition<'delete'> => ({
    url: destroy.url(args, options),
    method: 'delete',
})

/**
* @see \App\Http\Controllers\SimulationCostAllocationController::destroy
* @see app/Http/Controllers/SimulationCostAllocationController.php:78
* @route '/simulations/{simulation}/costs/{type}/{cost}/allocations/{project}'
*/
const destroyForm = (args: { simulation: number | { id: number }, type: string | number, cost: string | number, project: string | number } | [simulation: number | { id: number }, type: string | number, cost: string | number, project: 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\SimulationCostAllocationController::destroy
* @see app/Http/Controllers/SimulationCostAllocationController.php:78
* @route '/simulations/{simulation}/costs/{type}/{cost}/allocations/{project}'
*/
destroyForm.delete = (args: { simulation: number | { id: number }, type: string | number, cost: string | number, project: string | number } | [simulation: number | { id: number }, type: string | number, cost: string | number, project: 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 simulationCostAllocations = {
    update: Object.assign(update, update),
    destroy: Object.assign(destroy, destroy),
}

export default simulationCostAllocations