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

import { oc } from '@orpc/contract'
import * as z from 'zod'

import {
  zConsoleSsoOAuth2LoginResponse,
  zConsoleSsoOidcLoginResponse,
  zConsoleSsoSamlLoginResponse,
  zWebAppAuthGetGroupSubjectsQuery,
  zWebAppAuthGetGroupSubjectsResponse,
  zWebAppAuthGetWebAppAccessModeQuery,
  zWebAppAuthGetWebAppAccessModeResponse,
  zWebAppAuthGetWebAppWhitelistSubjectsQuery,
  zWebAppAuthGetWebAppWhitelistSubjectsResponse,
  zWebAppAuthIsUserAllowedToAccessWebAppQuery,
  zWebAppAuthIsUserAllowedToAccessWebAppResponse,
  zWebAppAuthSearchForWhilteListCandidatesQuery,
  zWebAppAuthSearchForWhilteListCandidatesResponse,
  zWebAppAuthUpdateWebAppWhitelistSubjectsBody,
  zWebAppAuthUpdateWebAppWhitelistSubjectsResponse,
} from './zod.gen'

export const oAuth2Login = oc
  .route({
    inputStructure: 'detailed',
    method: 'GET',
    operationId: 'ConsoleSSO_OAuth2Login',
    path: '/enterprise/sso/oauth2/login',
    tags: ['ConsoleSSO'],
  })
  .output(zConsoleSsoOAuth2LoginResponse)

export const oidcLogin = oc
  .route({
    inputStructure: 'detailed',
    method: 'GET',
    operationId: 'ConsoleSSO_OIDCLogin',
    path: '/enterprise/sso/oidc/login',
    tags: ['ConsoleSSO'],
  })
  .output(zConsoleSsoOidcLoginResponse)

export const samlLogin = oc
  .route({
    inputStructure: 'detailed',
    method: 'GET',
    operationId: 'ConsoleSSO_SAMLLogin',
    path: '/enterprise/sso/saml/login',
    tags: ['ConsoleSSO'],
  })
  .output(zConsoleSsoSamlLoginResponse)

export const consoleSso = {
  oAuth2Login,
  oidcLogin,
  samlLogin,
}

export const getWebAppAccessMode = oc
  .route({
    inputStructure: 'detailed',
    method: 'GET',
    operationId: 'WebAppAuth_GetWebAppAccessMode',
    path: '/enterprise/webapp/app/access-mode',
    tags: ['WebAppAuth'],
  })
  .input(z.object({ query: zWebAppAuthGetWebAppAccessModeQuery.optional() }))
  .output(zWebAppAuthGetWebAppAccessModeResponse)

export const updateWebAppWhitelistSubjects = oc
  .route({
    inputStructure: 'detailed',
    method: 'POST',
    operationId: 'WebAppAuth_UpdateWebAppWhitelistSubjects',
    path: '/enterprise/webapp/app/access-mode',
    tags: ['WebAppAuth'],
  })
  .input(z.object({ body: zWebAppAuthUpdateWebAppWhitelistSubjectsBody }))
  .output(zWebAppAuthUpdateWebAppWhitelistSubjectsResponse)

export const searchForWhilteListCandidates = oc
  .route({
    inputStructure: 'detailed',
    method: 'GET',
    operationId: 'WebAppAuth_SearchForWhilteListCandidates',
    path: '/enterprise/webapp/app/subject/search',
    tags: ['WebAppAuth'],
  })
  .input(z.object({ query: zWebAppAuthSearchForWhilteListCandidatesQuery.optional() }))
  .output(zWebAppAuthSearchForWhilteListCandidatesResponse)

export const getWebAppWhitelistSubjects = oc
  .route({
    inputStructure: 'detailed',
    method: 'GET',
    operationId: 'WebAppAuth_GetWebAppWhitelistSubjects',
    path: '/enterprise/webapp/app/subjects',
    tags: ['WebAppAuth'],
  })
  .input(z.object({ query: zWebAppAuthGetWebAppWhitelistSubjectsQuery.optional() }))
  .output(zWebAppAuthGetWebAppWhitelistSubjectsResponse)

export const getGroupSubjects = oc
  .route({
    inputStructure: 'detailed',
    method: 'GET',
    operationId: 'WebAppAuth_GetGroupSubjects',
    path: '/enterprise/webapp/group/subjects',
    tags: ['WebAppAuth'],
  })
  .input(z.object({ query: zWebAppAuthGetGroupSubjectsQuery.optional() }))
  .output(zWebAppAuthGetGroupSubjectsResponse)

export const isUserAllowedToAccessWebApp = oc
  .route({
    inputStructure: 'detailed',
    method: 'GET',
    operationId: 'WebAppAuth_IsUserAllowedToAccessWebApp',
    path: '/enterprise/webapp/permission',
    tags: ['WebAppAuth'],
  })
  .input(z.object({ query: zWebAppAuthIsUserAllowedToAccessWebAppQuery.optional() }))
  .output(zWebAppAuthIsUserAllowedToAccessWebAppResponse)

export const webAppAuth = {
  getWebAppAccessMode,
  updateWebAppWhitelistSubjects,
  searchForWhilteListCandidates,
  getWebAppWhitelistSubjects,
  getGroupSubjects,
  isUserAllowedToAccessWebApp,
}

export const contract = {
  consoleSso,
  webAppAuth,
}
