import { businessMemberInfo } from '@/entities/business-member/api/use-business-member-info-mutation';
import { 
  API_BASE_URL,
  API_URL_KEY,
  API_PARAM
} from './../constants/url';

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



  /* transaction Management - 거래관리 API */
  allTransactionList: () => {
    // POST: 거래 내역 조회
    return `${API_BASE_URL}/api/v1/${API_URL_KEY}/transaction/list`;
  },

  allTransactionListSummary: () => {
    // POST: 거래 내역 합계 조회
    return `${API_BASE_URL}/api/v1/${API_URL_KEY}/transaction/list/summary`;
  },
  downloadExcel: () => {
    // POST: 거래 엑셀 다운로드
    return `${API_BASE_URL}/api/v1/${API_URL_KEY}/transaction/download/excel`;
  },
  downloadConfirmation: () => {
    // POST: 거래 확인서 다운로드
    return `${API_BASE_URL}/api/v1/${API_URL_KEY}/transaction/download/confirmation`;
  },
  allTransactionDetail: () => {
    // POST: 거래내역 상세
    return `${API_BASE_URL}/api/v1/${API_URL_KEY}/transaction/detail`;
  },
  allTransactionCancel: () => {
    // POST: 거래취소 요청
    return `${API_BASE_URL}/api/v1/${API_URL_KEY}/transaction/cancel`;
  },
  allTransactionCancelInfo: () => {
    // POST: 거래취소 정보 조회
    return `${API_BASE_URL}/api/v1/${API_URL_KEY}/transaction/cancel-info`;
  },


  /* Cash Receipt Management - 현금영수증 API */
  cashReceiptList: () => {
    // POST: 현금영수증 목록 조회
    return `${API_BASE_URL}/api/v1/${API_URL_KEY}/cash-receipt/list`;
  },
  cashReceiptDetail: () => {
    // POST: 현금영수증 상세 조회
    return `${API_BASE_URL}/api/v1/${API_URL_KEY}/cash-receipt/detail`;
  },
  cashReceiptPurposeUpdate: () => {
    // POST: 현금영수증 용도 변경
    return `${API_BASE_URL}/api/v1/${API_URL_KEY}/cash-receipt/purpose/update`;
  },
  cashReceiptManualIssue: () => {
    // POST: 현금영수증 용도 변경
    return `${API_BASE_URL}/api/v1/${API_URL_KEY}/cash-receipt/manual/issue`;
  },
  

  /* Escro Management - 에스크로 API */
  escrowList: () => {
    // POST: 에스크로 목록 조회
    return `${API_BASE_URL}/api/v1/escrows/list`;
  },
  escrowDetail: () => {
    // POST: 에스크로 목록 상세 조회
    return `${API_BASE_URL}/api/v1/escrows/detail`;
  },
  escrowMailResend: () => {
    // POST: 에스크로 메일 재발송
    return `${API_BASE_URL}/api/v1/escrows/mail/resend`;
  },
  

  /* Billing Management - 빌링 API */
  billingList: () => {
    // POST: 빌링 목록 조회
    return `${API_BASE_URL}/api/v1/${API_URL_KEY}/billing/list`;
  },
  billingDetail: () => {
    // POST: 빌링 상세 조회
    return `${API_BASE_URL}/api/v1/${API_URL_KEY}/billing/detail`;
  },
  billingCharge: () => {
    // POST: 빌링 결제 신청
    return `${API_BASE_URL}/api/v1/${API_URL_KEY}/billing/charge`;
  },

  settlementList: () => {
    return `${API_BASE_URL}/api/v1/${API_URL_KEY}/transaction/list`;
  },

  businessMemberInfo: () => {
    return `${API_BASE_URL}/api/v1/${API_URL_KEY}/transaction/detail`;
  },

  /* 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`;
  },
  
  /* Counsel Management - 문의상담 API */
  qnaList: () => {
    // POST: 1:1 문의 목록 조회
    return `${API_BASE_URL}/api/v1/${API_URL_KEY}/counsel/list`;
  },
  qnaSave: () => {  
    // POST: 1:1 문의 등록
    return `${API_BASE_URL}/api/v1/${API_URL_KEY}/counsel/save`;
  },

  /* FAQ Management - FAQ(자주 묻는 질문) API */
  faqList: () => {
    // POST: FAQ 목록 조회
    return `${API_BASE_URL}/api/v1/${API_URL_KEY}/faq/list`;
  },

  /* Notice Management - 공지사항 API */
  noticeList: () => {
    // POST: 공지사항 목록 조회
    return `${API_BASE_URL}/api/v1/${API_URL_KEY}/notice/list`;
  },
  noticeDetail: () => {
    // POST: 공지사항 목록 조회
    return `${API_BASE_URL}/api/v1/${API_URL_KEY}/notice/detail`;
  },

  /* Extension Management - 부가서비스 API */
  extensionSmsResend: () => {  
    // POST: SMS 결제 통보 > SMS 재발송
    return `${API_BASE_URL}/api/v1/${API_URL_KEY}/extension/sms/resend`;
  },
  extensionSmsList: () => {  
    // POST: SMS 결제 통보 목록 조회
    return `${API_BASE_URL}/api/v1/${API_URL_KEY}/extension/sms/list`;
  },
  extensionSmsDownloadExcel: () => {  
    // POST: SMS 결제 통보 엑셀 다운
    return `${API_BASE_URL}/api/v1/${API_URL_KEY}/extension/sms/download/excel`;
  },
  extensionSmsDetail: () => {  
    // POST: SMS 결제 통보 상세 조회
    return `${API_BASE_URL}/api/v1/${API_URL_KEY}/extension/sms/detail`;
  },
  extensionList: () => {  
    // POST: 부가서비스 조회
    return `${API_BASE_URL}/api/v1/${API_URL_KEY}/extension/list`;
  },
  extensionKeyinList: () => {  
    // POST: KEY-IN 결제 목록 조회
    return `${API_BASE_URL}/api/v1/${API_URL_KEY}/extension/keyin/list`;
  },
  extensionKeyinDownloadExcel: () => {  
    // POST: KEY-IN 결제 엑셀 다운
    return `${API_BASE_URL}/api/v1/${API_URL_KEY}/extension/keyin/download/excel`;
  },
  extensionKeyinApply: () => {  
    // POST: KEY-IN 결제 > 결제 신청
    return `${API_BASE_URL}/api/v1/${API_URL_KEY}/extension/keyin/apply`;
  },
  extensionArsResend: () => {  
    // POST: SMS 신용카드 ARS 결제 > SMS 재전송
    return `${API_BASE_URL}/api/v1/${API_URL_KEY}/extension/ars/resend`;
  },
  extensionArsList: () => {  
    // POST: 신용카드 ARS 결제 > 목록 조회
    return `${API_BASE_URL}/api/v1/${API_URL_KEY}/extension/ars/list`;
  },
  extensionArsDownloadExcel: () => {  
    // POST: 신용카드 ARS 결제 > 엑셀 다운
    return `${API_BASE_URL}/api/v1/${API_URL_KEY}/extension/ars/download/excel`;
  },
  extensionArsDetail: () => {  
    // POST: 신용카드 ARS 결제 > 상세 내용 조회
    return `${API_BASE_URL}/api/v1/${API_URL_KEY}/extension/ars/detail`;
  },
  extensionArsApply: () => {  
    // POST: 신용카드 ARS 결제 > 결제 신청
    return `${API_BASE_URL}/api/v1/${API_URL_KEY}/extension/ars/apply`;
  },
  extensionAlimtalkSettingSave: () => {  
    // POST: 알림톡 결제 통보 > 서비스 설정 저장
    return `${API_BASE_URL}/api/v1/${API_URL_KEY}/extension/alimtalk/setting/save`;
  },
  extensionAlimtalkSettingDetail: () => {  
    // POST: 알림톡 결제 통보 > 서비스 설정 목록 조회
    return `${API_BASE_URL}/api/v1/${API_URL_KEY}/extension/alimtalk/setting/detail`;
  },
  extensionAlimtalkList: () => {  
    // POST: 알림톡 결제 통보 목록 조회
    return `${API_BASE_URL}/api/v1/${API_URL_KEY}/extension/alimtalk/list`;
  },
  extensionAlimtalkDownloadExcel: () => {  
    // POST: 알림톡 결제 통보 엑셀 다운
    return `${API_BASE_URL}/api/v1/${API_URL_KEY}/extension/alimtalk/download/excel`;
  },
  extensionAlimtalkDetail: () => {  
    // POST: 알림톡 결제 통보 상세 조회
    return `${API_BASE_URL}/api/v1/${API_URL_KEY}/extension/alimtalk/detail`;
  },

  /* 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;
};
