import { 
  API_BASE_URL,
  API_AUTH_BASE_URL,
  API_URL_KEY,
} from './../constants/url';

// all api URL
export const API_URL = {
  /* AUTH */
  login: () => {                        
    // AUTH-API-001
    return `${API_AUTH_BASE_URL}/auth/v1/${API_URL_KEY}/login`;
  },
  delegatedLogin: () => {
    // AUTH-API-002               
    return `${API_AUTH_BASE_URL}/auth/v1/${API_URL_KEY}/delegated-login`;
  },
  delegatedLoginAuthentication: () => {
    // AUTH-API-003
    return `${API_AUTH_BASE_URL}/auth/v1/${API_URL_KEY}/delegated-login/authentication`;
  },
  logout: () => {
    // AUTH-API-004 
    return `${API_AUTH_BASE_URL}/auth/v1/${API_URL_KEY}/logout`;
  },
  refresh: () => {
    // AUTH-API-005
    return `${API_AUTH_BASE_URL}/auth/v1/${API_URL_KEY}/refresh`;
  },
  verify: () => {
    // AUTH-API-006
    return `${API_AUTH_BASE_URL}/auth/v1/${API_URL_KEY}/verify`;
  },
  emailSend: () => {
    // AUTH-API-007
    return `${API_AUTH_BASE_URL}/auth/v1/${API_URL_KEY}/email/send`;
  },
  emailVerify: () => {
    // AUTH-API-008
    return `${API_AUTH_BASE_URL}/auth/v1/${API_URL_KEY}/email/verify`;
  },
  phoneSend: () => {
    // AUTH-API-009
    return `${API_AUTH_BASE_URL}/auth/v1/${API_URL_KEY}/phone/send`;
  },
  phoneVerify: () => {
    // AUTH-API-010
    return `${API_AUTH_BASE_URL}/auth/v1/${API_URL_KEY}/phone/verify`;
  },
  fidoRegisterBegin: () => {
    // AUTH-API-011
    return `${API_AUTH_BASE_URL}/auth/v1/${API_URL_KEY}/fido/register/begin`;
  },
  fidoRegisterComplete: () => {
    // AUTH-API-012
    return `${API_AUTH_BASE_URL}/auth/v1/${API_URL_KEY}/fido/register/complete`;
  },
  fidoLoginBegin: () => {
    // AUTH-API-013
    return `${API_AUTH_BASE_URL}/auth/v1/${API_URL_KEY}/fido/login/begin`;
  },
  fidoLoginComplete: () => {
    // AUTH-API-014
    return `${API_AUTH_BASE_URL}/auth/v1/${API_URL_KEY}/fido/login/complete`;
  },

  /* Code Management 코드 관리 API */
  codesSelect: () => {
    // GET: 전체 코드 조회 (캐시)
    // POST: 조건별 코드 조회
    return `${API_BASE_URL}/api/v1/${API_URL_KEY}/codes/select`;         
  },
  codesListByCodeCl: (codeCl: string) => {
    // GET: 특정 CodelCl 코드 리스트 조회 (캐시);
    return `${API_BASE_URL}/api/v1/${API_URL_KEY}/codes/list/${codeCl}`;
  },
  codesGroupByCodeCl: (codeCl: string) => {
    // GET: 특정 CodeCl 그룹 조회 (캐시)
    return `${API_BASE_URL}/api/v1/${API_URL_KEY}/codes/group/${codeCl}`;
  },
  codesCacheStatus: () => {
    // GET: 캐시 상태 조회
    return `${API_BASE_URL}/api/v1/${API_URL_KEY}/codes/cache/status`;
  },
  codesCacheRefresh: () => {
    // POST: 전체 캐시 갱신
    return `${API_BASE_URL}/api/v1/${API_URL_KEY}/codes/cache/refresh`;
  },
  codesCacheRefreshByCodelCl: (codeCl: string) => {
    // POST: 특정 CodeCl 캐시 갱신
    return `${API_BASE_URL}/api/v1/${API_URL_KEY}/codes/cache/refresh/${codeCl}`;
  },

  /* User Management - 사용자 관리 API */
  userExistsUserid: () => {
    // 중복 사용자 ID 확인
    return `${API_BASE_URL}/api/v1/${API_URL_KEY}/user/exists/userid`;
  },
  userCreate: () => {
    // 사용자 추가
    return `${API_BASE_URL}/api/v1/${API_URL_KEY}/user/create`;
  },

  /* Empty Token API Management - jwt 토큰이 없는 API 관리 */
  emptyTokenVerifyCode: () => {
    // POST: 인증 코드 검증
    return `${API_BASE_URL}/api/v1/empty-token/${API_URL_KEY}/verify/code`;
  },
  emptyTokenFindSendCode: () => {
    // POST: 인증 코드 전솔
    return `${API_BASE_URL}/api/v1/empty-token/${API_URL_KEY}/find-send/code`;
  },
  emptyTokenChange: () => {
    // POST: 비밀번호 변경
    return `${API_BASE_URL}/api/v1/empty-token/${API_URL_KEY}/change`;
  },
  emptyTokenAddSendCode: () => {
    // POST: 인증 코드 전송
    return `${API_BASE_URL}/api/v1/empty-token/${API_URL_KEY}/add-send/code`;
  }

};

export type API_URL_TYPE = typeof API_URL;

export const WHITE_LIST_URLS: string[] = [
  API_URL.login(),
  API_URL.delegatedLogin(),
  API_URL.delegatedLoginAuthentication(),
  API_URL.logout(),
  API_URL.refresh(),
  API_URL.verify(),
  API_URL.emailSend(),
  API_URL.emailVerify(),
  API_URL.phoneSend(),
  API_URL.phoneVerify(),
  API_URL.fidoRegisterBegin(),
  API_URL.fidoRegisterComplete(),
  API_URL.fidoLoginBegin(),
  API_URL.fidoLoginComplete(),
];

export const getApiPathname = (url: string) => {
  return new URL(url).pathname;
};
