import { DefaulResponsePagination, DefaultRequestPagination } from '@/entities/common/model/types';
import { PayoutContent } from './payout/types';
import { FundAccountTransferContentItem, FundAccountResultContentItem } from './fund-account/types';
import { ArsListContent } from './ars/types';
import { AlimtalkListContent } from './alimtalk/types';
import { SmsPaymentListItem } from './sms-payment/types';
import type { ExtensionSmsDetailResponse } from './sms-payment/types';

// ========================================
// 공통 Enums 및 타입들
// ========================================

export enum SortByKeys {
  New = 'New',
  Amount = 'Amount',
}

export enum ProcessResult {
  ALL = 'ALL',
  SUCCESS = 'SUCCESS',
  FAIL = 'FAIL'
}

export interface SortOptionsBoxProps {
  sortBy: SortByKeys;
  onClickToSort: (sortBy: SortByKeys) => void;
}

// 부가서비스 카테고리 enum
export enum AdditionalServiceCategory {
  KeyInPayment = 'KeyInPayment',
  AccountHolderAuth = 'AccountHolderAuth',
  AccountHolderSearch = 'AccountHolderSearch',
  LinkPaymentHistory = 'LinkPaymentHistory',
  LinkPaymentWait = 'LinkPaymentWait',
  FundAccountTransfer = 'FundAccountTransfer',
  FundAccountResult = 'FundAccountResult',
  SettlementAgency = 'SettlementAgency',
  SMSPayment = 'SMSPayment',
  Payout = 'Payout',
  Ars = 'Ars',
  Alimtalk = 'Alimtalk',
}

// ========================================
// 상세정보 Interface
// ========================================

export interface TitleInfo {
  amount?: number,
  corpName?: string,
  accountNo?: string,
  accountName?: string,
  bankName?: string,
  requestDate?: string,
  sendDate?: string,
  scheduledSendDate?: string
}

export interface DetailInfo {
  accountName?: string; // 예금주
  requestDate?: string; // 조회 일시
  resultStatus?: string; // 결과
  bankName?: string; // 은행 명
  failureReason?: string; // 실패사유
  accountNo?: string; // 계좌번호
  requestWay?: string; //요청 구분

  mid?: string;
  companyName?: string;
  email: string;
  phoneNumber: string;
  goodsName: string;
  moid: string;
  transferStatus: AuthAndTransferStatus;

}

export interface PaymentInfo {
  processStatus?: string;
  requestDate?: string;
  email?: string;
  phoneNumber?: string;
  goodsName?: string;
  moid?: string;
  buyerName?: string;
  sendMethod?: string;
  sendDate?: string;
  failCount?: number;
  paymentStatus?: string;
  paymentMethod?: string;
  paymentDate?: string;
  paymentLimitDate?: string;
}

// 상세정보 Info Enum
export enum InfoWrapKeys {
  Title = 'Title',
  Transaction = 'Transaction',
  Payment = 'Payment',
  Detail = 'Detail'
};


// ========================================
// 공통 Filter 타입들
// ========================================

export interface FilterProps {
  filterOn: boolean;
  setFilterOn: (filterOn: boolean) => void;
}

// ========================================
// SMS 결제 통보 관련 타입들
// ========================================


// ========================================
// 키인결제 관련 타입들
// ========================================

export enum KeyInPaymentTransactionStatus {
  ALL = 'ALL',
  APPROVAL = 'APPROVAL',
  PRE_CANCEL = 'PRE_CANCEL',
  POST_CANCEL = 'POST_CANCEL'
}

export interface KeyInPaymentListItem {
  tid?: string;
  paymentDate?: string;
  paymentStatus?: string;
  amount?: number;
}

export interface KeyInPaymentListProps {
  additionalServiceCategory: AdditionalServiceCategory;
  listItems: Record<string, Array<ListItemProps>>;
}

export interface KeyInPaymentFilterProps extends FilterProps {
  mid: string,
  startDate: string;
  endDate: string;
  transactionStatus: KeyInPaymentTransactionStatus;
  minAmount?: number;
  maxAmount?: number;
  setMid: (mid: string) => void;
  setStartDate: (startDate: string) => void;
  setEndDate: (endDate: string) => void;
  setTransactionStatus: (transactionStatus: KeyInPaymentTransactionStatus) => void;
  setMinAmount: (minAmount?: number) => void;
  setMaxAmount: (maxAmount?: number) => void;
}

// ========================================
// 계좌 점유 조회 관련 타입들
// ========================================
export enum AuthAndTransferStatus {
  ALL = "ALL",
  REQUEST = "REQUEST",
  SUCCESS = "SUCCESS",
  FAIL = "FAIL"
}

export interface AccountHolderAuthListItem {
  tid?: string;
  accountName?: string;
  accountNo?: string;
  requestDate?: string;
  bankName?: string;
  transferStatus?: AuthAndTransferStatus;
}
export interface AccountHolderAuthListProps {
  listItems: Record<string, Array<ListItemProps>>;
  mid: string;
}
export interface AccountHolderAuthFilterProps extends FilterProps {
  mid: string;
  startDate: string;
  endDate: string;
  authStatus: AuthAndTransferStatus;
  setMid: (mid: string) => void;
  setStartDate: (startDate: string) => void;
  setEndDate: (endDate: string) => void;
  setAuthStatus: (authStatus: AuthAndTransferStatus) => void;

}
// ========================================
// 계좌성명 조회 관련 타입들
// ========================================

export enum AccountHolderSearchType {
  ACCOUNT_NAME = 'ACCOUNT_NAME',
  ACCOUNT_NO = 'ACCOUNT_NO'
}

export interface AccountHolderSearchListItem {
  tid?: string;
  accountNo?: string;
  requestDate?: string;
  bankName?: string;
  resultStatus?: string;
}

export interface AccountHolderSearchListProps {
  listItems: Record<string, Array<ListItemProps>>;
  mid: string;
}

export interface AccountHolderSearchFilterProps extends FilterProps {
  mid: string;
  searchType: AccountHolderSearchType;
  searchKeyword: string;
  startDate: string;
  endDate: string;
  bank: string;
  processResult: ProcessResult;
  setMid: (mid: string) => void;
  setSearchType: (searchType: AccountHolderSearchType) => void;
  setSearchKeyword: (searchKeyWorld: string) => void;
  setStartDate: (startDate: string) => void;
  setEndDate: (endDate: string) => void;
  setBank: (bank: string) => void;
  setProcessResult: (processResult: ProcessResult) => void;
}

// ========================================
// 링크결제 관련 타입들
// ========================================

export enum LinkPaymentTabKeys {
  ShippingHistory = 'ShippingHistory',
  PendingSend = 'PendingSend'
}

export interface LinkPaymentTabProps {
  activeTab: LinkPaymentTabKeys;
}

export enum LinkPaymentSearchType {
  ALL = "ALL",
  PHONE = "PHONE",
  EMAIL = "EMAIL"
}

export enum LinkPaymentSendMethod {
  ALL = "ALL",
  SMS = "SMS",
  EMAIL = "EMAIL",
  KAKAO = "KAKAO"
}

export enum LinkPaymentTransactionStatus {
  ALL = "ALL",
  ACTIVATE = "ACTIVATE",
  DEPOSIT_REQUEST = "DEPOSIT_REQUEST",
  TRANSACTION_COMPLETE = "TRANSACTION_COMPLETE",
  TRANSACTION_FAIL = "TRANSACTION_FAIL",
  INACTIVE = "INACTIVE"
}

export enum LinkPaymentSendingStatus {
  ALL = "ALL",
  SEND_REQUEST = "SEND_REQUEST",
  SEND_CANCEL = "SEND_CANCEL"
}

export enum IdentityType {
  INDIVIDUAL = "INDIVIDUAL",
  CORPORATE = "CORPORATE"
}

export enum Language {
  KR = "KR",
  EN = "EN"
}

export enum LinkContentType {
  BASIC = "BASIC",
  ADDITIONAL = "ADDITIONAL"
}

export interface LinkPaymentHistoryListItem {
  tid?: string;
  // TODO : buyerName 필요
  paymentDate?: string;
  paymentStatus?: string;
  sendDate?: string;
  sendStatus?: string;
  sendMethod?: string;
  amount?: number;
}

export interface LinkPaymentWaitListItem {
  tid?: string;
  scheduledSendDate?: string;
  sendMethod?: string;
  processStatus?: string;
  // TODO: buyerName,phoneNumber 필요
  amount?: number;
}

export interface LinkPaymentHistoryListProps {
  additionalServiceCategory: AdditionalServiceCategory;
  listItems: Record<string, Array<ListItemProps>>;
}

export interface LinkPaymentWaitListProps {
  additionalServiceCategory: AdditionalServiceCategory;
  listItems: Record<string, Array<ListItemProps>>;
}

export interface LinkPaymentHistoryFilterProps extends FilterProps {
  mid: string;
  searchType: LinkPaymentSearchType;
  searchKeyword: string;
  startDate: string;
  endDate: string;
  transactionStatus: LinkPaymentTransactionStatus;
  processResult: ProcessResult;
  sendMethod: LinkPaymentSendMethod;
  setMid: (mid: string) => void;
  setSearchType: (searchType: LinkPaymentSearchType) => void;
  setSearchKeyword: (searchKeyWorld: string) => void;
  setStartDate: (startDate: string) => void;
  setEndDate: (endDate: string) => void;
  setTransactionStatus: (transactionStatus: LinkPaymentTransactionStatus) => void;
  setProcessResult: (processResult: ProcessResult) => void;
  setSendMethod: (sendMethod: LinkPaymentSendMethod) => void;
}

export interface LinkPaymentWaitFilterProps extends FilterProps {
  mid: string;
  searchType: LinkPaymentSearchType;
  searchKeyword: string;
  startDate: string;
  endDate: string;
  sendMethod: LinkPaymentSendMethod;
  sendingStatus: LinkPaymentSendingStatus;
  setMid: (mid: string) => void;
  setSearchType: (searchType: LinkPaymentSearchType) => void;
  setSearchKeyword: (searchKeyWorld: string) => void;
  setStartDate: (startDate: string) => void;
  setEndDate: (endDate: string) => void;
  setSendMethod: (sendMethod: LinkPaymentSendMethod) => void;
  setSendingStatus: (sendingStatus: LinkPaymentSendingStatus) => void;
}

export enum DetailInfoSectionKeys {
  Title = 'Title',
  Detail = 'Detail',
  Payment = 'Payment',
  Deets = 'Deets'
}

export interface DetailResponse {
  titleInfo?: TitleInfo //최상단 섹션
  detailInfo?: DetailInfo // '상세 정보' 섹션
  paymentInfo?: PaymentInfo // '결제 정보' 섹션
}

export interface DetailInfoSectionProps extends DetailResponse {
  additionalServiceCategory?: AdditionalServiceCategory
  show?: boolean;
  onClickToShowInfo?: (info: DetailInfoSectionKeys) => void;
}

// ========================================
// 정산기관 관련 타입들
// ========================================

export enum SettlementAgencyTabKeys {
  Manage = 'Manage',
  Deposit = 'Deposit',
  Member = 'Member',
}

export interface SettlementAgencyTabProps {
  activeTab: SettlementAgencyTabKeys;
}

export interface SettlementAgencyBottomAgreeProps {
  bottomAgreeOn: boolean;
  setBottomAgreeOn: (bottomAgreeOn: boolean) => void;
}

// ========================================
// 공통 리스트 관련 타입들
// ========================================

export interface ListItemProps extends
  KeyInPaymentListItem, AccountHolderSearchListItem,
  AccountHolderAuthListItem, LinkPaymentHistoryListItem,
  LinkPaymentWaitListItem, SmsPaymentListItem,
  PayoutContent, FundAccountTransferContentItem,
  FundAccountResultContentItem,
  ArsListContent, AlimtalkListContent {
  additionalServiceCategory?: AdditionalServiceCategory;
  mid?: string;
  onResendClick?: (mid: string, tid: string) => void;
}

export interface ListDateGroupProps {
  additionalServiceCategory?: AdditionalServiceCategory;
  date?: string;
  items?: Array<ListItemProps>;
  mid?: string;
  onResendClick?: (mid: string, tid: string) => void;
}

export interface AdditionalServiceListProps {
  additionalServiceCategory: AdditionalServiceCategory;
  listItems: Record<string, Array<ListItemProps>>;
}

// ========================================
// 확장 서비스 API 타입들
// ========================================

export interface ExtensionRequestParams {
  mid: string;
}
// 링크 결제 - 발송,대기 조회 확장 서비스
// ========================================
export interface ExtensionLinkPayHistoryListParams extends ExtensionRequestParams {
  searchCl: string;
  searchValue: string;
  paymentMethod: string;
  fromDate: string;
  toDate: string;
  paymentStatus: string;
  sendStatus: string;
  sendMethod: string;
  page?: DefaultRequestPagination;
}

export interface ExtensionLinkPayHistoryListResponse extends DefaulResponsePagination {
  content: Array<ListItemProps>
}

export interface ExtensionLinkPayHistoryDownloadExcelParams extends ExtensionRequestParams {
  searchCl: string;
  searchValue: string;
  paymentMethod: string;
  fromDate: string;
  toDate: string;
  paymentStatus: string;
  sendStatus: string;
  sendMethod: string;
}

export interface ExtensionLinkPayHistoryDownloadExcelRespone {
  status: boolean;
}

export interface ExtensionLinkPayRequestParams extends ExtensionRequestParams {
  sendMethod: string;
  goodsName: string;
  amount: number;
  moid: string;
  paymentExpiryDate: string;
  buyerName: string;
  email: string;
  phoneNumber: string;
  isIdentity: boolean;
  identityType: IdentityType;
  identityValue: string;
  language: Language;
  linkContentType: LinkContentType;
}

export interface ExtensionLinkPayRequestResponse {
  status: boolean
}

export interface LinkPaymentFormData {
  // Step 1
  mid: string;
  sendMethod: LinkPaymentSendMethod;
  goodsName: string;
  amount: number;
  moid: string;
  paymentExpiryDate: string;
  // Step 2
  buyerName: string;
  email: string;
  phoneNumber: string;
  isIdentity: boolean;
  identityType: IdentityType;
  identityValue: string;
  language: Language;
  linkContentType: LinkContentType;
}

export interface ExtensionLinkPayHistoryDetailParams extends ExtensionRequestParams {
  tid: string;
}

export interface ExtensionLinkPayHistoryDetailResponse {
  tid: string;
  amount: number;
  corpName: string;
  sendDate: string;
  buyerName: string;
  sendMethod: string;
  paymentStatus: string;
  failCount: number;
  paymentMethod: string;
  paymentDate: string;
  paymentLimitDate: string;
  email: string;
  phoneNumber: string;
  goodsName: string;
  moid: string;
}

export interface ExtensionLinkPayHistoryResendParams extends ExtensionRequestParams {
  tid: string;
}

export interface ExtensionLinkPayHistoryResendResponse {
  status: boolean
}


export interface ExtensionLinkPayWaitListParams extends ExtensionRequestParams {
  searchCl: string;
  searchValue: string;
  fromDate: string;
  toDate: string;
  sendStatus: string;
  sendMethod: string;
  processStatus: string;
  page?: DefaultRequestPagination;
}

export interface ExtensionLinkPayWaitListResponse extends DefaulResponsePagination {
  content: Array<ListItemProps>
}

export interface ExtensionLinkPayWaitDownloadExcelParams extends ExtensionRequestParams {
  searchCl: string;
  searchValue: string;
  fromDate: string;
  toDate: string;
  sendStatus: string;
  sendMethod: string;
  processStatus: string;
}

export interface ExtensionLinkPayWaitDownloadExcelRespone {
  status: boolean;
}

export interface ExtensionLinkPayWaitDetailParams extends ExtensionRequestParams {
  tid: string;
}

export interface ExtensionLinkPayWaitDetailResponse {
  tid: string;
  amount: number;
  corpName: string;
  scheduledSendDate: string;
  processStatus: string;
  requestDate: string;
  paymentLimitDate: string;
  sendMethod: string;
  buyerName: string
  email: string;
  phoneNumber: string;
  goodsName: string;
  moid: string;
}

export interface ExtensionLinkPayWaitDeleteParams extends ExtensionRequestParams {
  tid: string;
}

export interface ExtensionLinkPayWaitDeleteRespone {
  status: boolean
}

// 계좌 점유 인증 확장 서비스
// ========================================
export interface ExtensionAccountHolderAuthListParams extends ExtensionRequestParams {
  fromDate: string;
  toDate: string;
  authStatus: string;
  page?: DefaultRequestPagination;
}

export interface ExtensionAccountHolderAuthListResponse extends DefaulResponsePagination {
  content: Array<ListItemProps>
}

export interface ExtensionAccountHolderAuthDownloadExcelParams extends ExtensionRequestParams {
  mid: string;
  fromDate: string;
  toDate: string;
  authStatus: AuthAndTransferStatus;
}

export interface ExtensionAccountHolderAuthDownloadExcelResponse {
  status: boolean;
}

export interface ExtensionAccountHolderAuthDetailParams extends ExtensionRequestParams {
  tid: string;
}

export interface ExtensionAccountHolderAuthDetailResponse {
  tid: string;
  mid: string;
  accountName: string;
  accountNo: string;
  requestDate: string;
  companyName: string;
  bankName: string;
  transferStatus: AuthAndTransferStatus;
  failReason: string;
}

// 계좌 성명 조회 확장 서비스
// ========================================
export interface ExtensionAccountHolderSearchListParams extends ExtensionRequestParams { // Request
  searchCl: string;
  searchValue: string;
  fromDate: string;
  toDate: string;
  bankCode: string;
  resultStatus: string;
  page?: DefaultRequestPagination;
}
export interface ExtensionAccountHolderSearchListResponse extends DefaulResponsePagination { // Response
  content: Array<ListItemProps>
}

export interface ExtensionAccountHolderSearchDetailParams extends ExtensionRequestParams { // Request
  tid: string;
}

export interface ExtensionAccountHolderSearchDetailResponse {
  tid: string;
  accountNo: string;
  bankName: string;
  requestDate: string;
  accountName: string;
  resultStatus: string;
  failReason: string;
  requestWay: string;
}

export interface ExtensionAccountHolderSearchRequestParams extends ExtensionRequestParams {
  bankCode: string;
  accountNo: string;
}

export interface ExtensionAccountHolderSearchRequestResponse {
  status: boolean;
}

export interface ExtensionAccountHolderSearchDownloadExcelParams extends ExtensionRequestParams { // Request
  searchCl: string;
  searchValue: string;
  fromDate?: string;
  toDate?: string;
  bankCode: string;
  resultStatus: string;
}

export interface ExtensionAccountHolderSearchDownloadExcelResponse {
  status: boolean;
}
// ========================================


// KEY-IN 결제 확장 서비스
// ========================================
export interface ExtensionKeyinListParams extends ExtensionRequestParams {
  fromDate: string;
  toDate: string;
  paymentStatus: string;
  minAmount?: number;
  maxAmount?: number;
  page?: DefaultRequestPagination;
}

export interface ExtensionKeyinListItemProps {
  tid: string;
  paymentDate: string;
  paymentStatus: string;
  amount: number;
}

export interface ExtensionKeyinListResponse extends DefaulResponsePagination {
  content: Array<ExtensionKeyinListItemProps>
}

export interface ExtensionKeyinDownloadExcelParams extends ExtensionRequestParams {
  fromDate?: string;
  toDate?: string;
  paymentStatus?: string;
  minAmount?: number;
  maxAmount?: number;
}

export interface ExtensionKeyinDownloadExcelResponse {
  status: boolean
}

export interface ExtensionKeyinApplyParams extends ExtensionRequestParams {
  goodsName: string;
  amount: number;
  buyerName: string;
  email: string;
  phoneNumber: string;
  cardNo: string;
  cardExpirationDate: string;
  instmntMonth: string;
  moid: string;
}

export interface ExtensionKeyinApplyResponse {

}
// ========================================

// SMS 결제알림 확장 서비스
// ========================================
export interface ExtensionSmsResendParams extends ExtensionRequestParams {
  tid: string;
}

export interface ExtensionSmsResendResponse {

}

export interface ExtensionSmsListParams extends ExtensionRequestParams {
  searchCl: string;
  searchValue: string;
  fromDate: string;
  toDate: string;
  smsCl: string;
  page?: DefaultRequestPagination;
}

export interface ExtensionSmsListItemProps {
  mid: string;
  tid: string;
  paymentDate: string;
  paymentStatus: string;
  smsCl: string;
}

export interface ExtensionSmsListResponse extends DefaulResponsePagination {
  content: Array<ExtensionSmsListItemProps>
}

export interface ExtensionSmsDownloadExcelParams extends ExtensionRequestParams {
  searchCl: string;
  searchValue: string;
  fromDate: string;
  toDate: string;
  smsCl: string;
}

export interface ExtensionSmsDownloadExcelResponse {

}

export interface ExtensionSmsDetailParams extends ExtensionRequestParams {
  tid: string;
}

// ========================================


// 확장 서비스 목록 관련
export interface ExtensionListParams extends ExtensionRequestParams {

}

export interface activeExtensionListItem {
  extensionCode: string;
  extensionName: string;
  extensionInformation: string;
}

export interface availableExtensionListItem {
  extensionCode: string;
  extensionName: string;
  extensionInformation: string;
}

export interface ExtensionListItemProps {
  activeExtensionList: Array<activeExtensionListItem>;
  availableExtensionList: Array<availableExtensionListItem>;
}

export interface ExtensionListResponse extends DefaulResponsePagination {
  content: Array<ExtensionListItemProps>
}

// ========================================
// 기타 UI 컴포넌트 타입들
// ========================================

export interface IntroListItemProps {
  className?: string;
  serviceName?: string;
  serviceDesc?: string;
  icon?: string;
  path?: string;
}

export interface ArsCardPaymentFinishProps {
  requestSuccess: boolean;
  setRequestSuccess: (requestSuccess: boolean) => void;
}

