// This file is auto-generated by @hey-api/openapi-ts

import { oc } from '@orpc/contract'
import * as z from 'zod'
import {
  zGetOauthDataSourceBindingByProviderPath,
  zGetOauthDataSourceBindingByProviderQuery,
  zGetOauthDataSourceBindingByProviderResponse,
  zGetOauthDataSourceByProviderByBindingIdSyncPath,
  zGetOauthDataSourceByProviderByBindingIdSyncResponse,
  zGetOauthDataSourceByProviderPath,
  zGetOauthDataSourceByProviderResponse,
  zGetOauthPluginByProviderIdDatasourceGetAuthorizationUrlPath,
  zGetOauthPluginByProviderIdDatasourceGetAuthorizationUrlQuery,
  zGetOauthPluginByProviderIdDatasourceGetAuthorizationUrlResponse,
  zGetOauthPluginByProviderToolAuthorizationUrlPath,
  zGetOauthPluginByProviderToolAuthorizationUrlResponse,
  zPostOauthProviderAccountBody,
  zPostOauthProviderAccountResponse,
  zPostOauthProviderAuthorizeBody,
  zPostOauthProviderAuthorizeResponse,
  zPostOauthProviderBody,
  zPostOauthProviderResponse,
  zPostOauthProviderTokenBody,
  zPostOauthProviderTokenResponse,
} from './zod.gen'

/**
 * Bind OAuth data source with authorization code
 */
export const get = oc
  .route({
    description: 'Bind OAuth data source with authorization code',
    inputStructure: 'detailed',
    method: 'GET',
    operationId: 'getOauthDataSourceBindingByProvider',
    path: '/oauth/data-source/binding/{provider}',
    tags: ['console'],
  })
  .input(
    z.object({
      params: zGetOauthDataSourceBindingByProviderPath,
      query: zGetOauthDataSourceBindingByProviderQuery,
    }),
  )
  .output(zGetOauthDataSourceBindingByProviderResponse)

export const byProvider = {
  get,
}

export const binding = {
  byProvider,
}

/**
 * Sync data from OAuth data source
 */
export const get2 = oc
  .route({
    description: 'Sync data from OAuth data source',
    inputStructure: 'detailed',
    method: 'GET',
    operationId: 'getOauthDataSourceByProviderByBindingIdSync',
    path: '/oauth/data-source/{provider}/{binding_id}/sync',
    tags: ['console'],
  })
  .input(z.object({ params: zGetOauthDataSourceByProviderByBindingIdSyncPath }))
  .output(zGetOauthDataSourceByProviderByBindingIdSyncResponse)

export const sync = {
  get: get2,
}

export const byBindingId = {
  sync,
}

/**
 * Get OAuth authorization URL for data source provider
 */
export const get3 = oc
  .route({
    description: 'Get OAuth authorization URL for data source provider',
    inputStructure: 'detailed',
    method: 'GET',
    operationId: 'getOauthDataSourceByProvider',
    path: '/oauth/data-source/{provider}',
    tags: ['console'],
  })
  .input(z.object({ params: zGetOauthDataSourceByProviderPath }))
  .output(zGetOauthDataSourceByProviderResponse)

export const byProvider2 = {
  get: get3,
  byBindingId,
}

export const dataSource = {
  binding,
  byProvider: byProvider2,
}

export const get4 = oc
  .route({
    inputStructure: 'detailed',
    method: 'GET',
    operationId: 'getOauthPluginByProviderIdDatasourceGetAuthorizationUrl',
    path: '/oauth/plugin/{provider_id}/datasource/get-authorization-url',
    tags: ['console'],
  })
  .input(
    z.object({
      params: zGetOauthPluginByProviderIdDatasourceGetAuthorizationUrlPath,
      query: zGetOauthPluginByProviderIdDatasourceGetAuthorizationUrlQuery.optional(),
    }),
  )
  .output(zGetOauthPluginByProviderIdDatasourceGetAuthorizationUrlResponse)

export const getAuthorizationUrl = {
  get: get4,
}

export const datasource = {
  getAuthorizationUrl,
}

export const byProviderId = {
  datasource,
}

export const get5 = oc
  .route({
    inputStructure: 'detailed',
    method: 'GET',
    operationId: 'getOauthPluginByProviderToolAuthorizationUrl',
    path: '/oauth/plugin/{provider}/tool/authorization-url',
    tags: ['console'],
  })
  .input(z.object({ params: zGetOauthPluginByProviderToolAuthorizationUrlPath }))
  .output(zGetOauthPluginByProviderToolAuthorizationUrlResponse)

export const authorizationUrl = {
  get: get5,
}

export const tool = {
  authorizationUrl,
}

export const byProvider3 = {
  tool,
}

export const plugin = {
  byProviderId,
  byProvider: byProvider3,
}

export const post = oc
  .route({
    inputStructure: 'detailed',
    method: 'POST',
    operationId: 'postOauthProviderAccount',
    path: '/oauth/provider/account',
    tags: ['console'],
  })
  .input(z.object({ body: zPostOauthProviderAccountBody }))
  .output(zPostOauthProviderAccountResponse)

export const account = {
  post,
}

export const post2 = oc
  .route({
    inputStructure: 'detailed',
    method: 'POST',
    operationId: 'postOauthProviderAuthorize',
    path: '/oauth/provider/authorize',
    tags: ['console'],
  })
  .input(z.object({ body: zPostOauthProviderAuthorizeBody }))
  .output(zPostOauthProviderAuthorizeResponse)

export const authorize = {
  post: post2,
}

export const post3 = oc
  .route({
    inputStructure: 'detailed',
    method: 'POST',
    operationId: 'postOauthProviderToken',
    path: '/oauth/provider/token',
    tags: ['console'],
  })
  .input(z.object({ body: zPostOauthProviderTokenBody }))
  .output(zPostOauthProviderTokenResponse)

export const token = {
  post: post3,
}

export const post4 = oc
  .route({
    inputStructure: 'detailed',
    method: 'POST',
    operationId: 'postOauthProvider',
    path: '/oauth/provider',
    tags: ['console'],
  })
  .input(z.object({ body: zPostOauthProviderBody }))
  .output(zPostOauthProviderResponse)

export const provider = {
  post: post4,
  account,
  authorize,
  token,
}

export const oauth = {
  dataSource,
  plugin,
  provider,
}

export const contract = {
  oauth,
}
