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

import { DefaulResponsePagination, DefaultRequestPagination } from "@/entities/common/model/types";
import { AdditionalServiceCategory, DetailInfo, ExtensionRequestParams, FilterProps, IdentityType, Language, ListItemProps, PaymentInfo, ProcessResult, TitleInfo } from "../types";

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

export interface LinkPaymentTabProps {
  activeTab: LinkPaymentTabKeys;
}

export enum LinkPaymentSearchCl {
  PHONE = "PHONE_NUMBER",
  EMAIL = "EMAIL"
}

export enum LinkPaymentPaymentMethod {
  CARD = "CARD",
  BANK = "BANK",
  VIRTURE_BANK = "VIRTURE_BANK",
  PHONE = "PHONE",
  CULTURELAND = "CULTURELAND",
  SSG_MONEY = "SSG_MONEY",
  SSG_BANK = "SSG_BANK",
  CMS_BANK = "CMS_BANK",
  TMONEY_PAY = "TMONEY_PAY"
}

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

export enum LinkPaymentPaymentStatus {
  ALL = "",
  ACTIVATE = "ACTIVE",
  DEPOSIT_REQUEST = "DEPOSIT_REQUEST",
  PAYMENT_COMPLETE = "PAYMENT_COMPLETE",
  PAYMENT_FAIL = "PAYMENT_FAIL",
  INACTIVE = "INACTIVE"
}

export enum LinkPaymentSendStatus {
  ALL = "",
  SUCCESS = "SUCCESS",
  FAIL = "FAIL"
}

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

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

export enum LinkPaymentSeparateType {
  MAIN = "MAIN",
  SUB = "SUB"
}

export enum LinkPaymentSeparateAction {
  EXTEND = "EXTEND",
  DEACTIVATE = "DEACTIVATE"
}

export interface LinkPaymentHistoryListItem {
  requestId?: string;
  cursorId?: string;
  subReqId?: string;
  mid?: string;
  paymentMethod?: string;
  detailExposure?: string;
  sendDate?: string;
  buyerName?: string;
  receiverInfo?: string;
  orderId?: string;
  sendStatus?: string;
  paymentStatus?: string;
  sendMethod?: LinkPaymentSendMethod;
}

export interface LinkPaymentWaitListItem {
  requestId?: string;
  scheduledSendDate?: string;
  sendMethod?: LinkPaymentSendMethod;
  amount?: number;
  processStatus?: LinkPaymentProcessStatus;
  buyerName?: string;
  receiverInfo?: string;
}

export interface LinkPaymentHistoryListProps {
  additionalServiceCategory: AdditionalServiceCategory;
  listItems: Array<LinkPaymentHistoryListItem>;
  mid: string;
}

export interface LinkPaymentWaitListProps {
  additionalServiceCategory: AdditionalServiceCategory;
  listItems: Array<LinkPaymentWaitListItem>;
  mid: string;
}

export interface LinkPaymentHistoryFilterProps extends FilterProps {
  mid: string;
  searchCl: LinkPaymentSearchCl;
  searchValue: string;
  fromDate: string;
  toDate: string;
  paymentStatus: LinkPaymentPaymentStatus;
  sendStatus: LinkPaymentSendStatus;
  sendMethod: LinkPaymentSendMethod;
  setMid: (mid: string) => void;
  setSearchType: (searchType: LinkPaymentSearchCl) => void;
  setSearchKeyword: (searchKeyWorld: string) => void;
  setStartDate: (startDate: string) => void;
  setEndDate: (endDate: string) => void;
  setPaymentStatus: (transactionStatus: LinkPaymentPaymentStatus) => void;
  setSendStatus: (sendStatus: LinkPaymentSendStatus) => void;
  setSendMethod: (sendMethod: LinkPaymentSendMethod) => void;
}

export interface LinkPaymentWaitFilterProps extends FilterProps {
  mid: string;
  searchCl: LinkPaymentSearchCl;
  searchKeyword: string;
  startDate: string;
  endDate: string;
  sendMethod: LinkPaymentSendMethod;
  processStatus: LinkPaymentProcessStatus;
  setMid: (mid: string) => void;
  setSearchType: (searchType: LinkPaymentSearchCl) => void;
  setSearchKeyword: (searchKeyWorld: string) => void;
  setStartDate: (startDate: string) => void;
  setEndDate: (endDate: string) => void;
  setSendMethod: (sendMethod: LinkPaymentSendMethod) => void;
  setProcessStatus: (sendingStatus: LinkPaymentProcessStatus) => void;
}

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

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

export interface ExtensionLinkPayHistoryDownloadExcelParams extends ExtensionRequestParams {
  email: string;
  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;
  paymentLimitDate: string;
  buyerName: string;
  email?: string;
  phoneNumber?: string;
  isIdentity: boolean;
  identityType?: IdentityType;
  identityValue?: string;
  language: Language;
  linkContentType: LinkContentType;
}

export interface ExtensionLinkPayRequestResponse {
  status: boolean;
  error?: {
    root?: string;
    errKey?: string;
    code?: string;
    message?: string;
    timestamp?: string;
    details?: {
      validationErrors?: {
        [key: string]: string;
      }
    }
  }
}

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

export interface ExtensionLinkPayHistoryDetailParams {
  mid: string;
  requestId: string;
  subReqId: 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 {
  requestId: string;
  sendMethod?: string;
}

export interface ExtensionLinkPayHistoryResendResponse {
  status: boolean;
  data?: string;
  error?: {
    root?: string;
    errKey?: string;
    code?: string;
    message?: string;
    timestamp?: string;
    details?: {
      [key: string]: string;
    };
  };
}


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

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

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

export interface ExtensionLinkPayWaitDownloadExcelRespone {
  status: boolean;
}

export interface ExtensionLinkPayWaitDetailParams extends ExtensionRequestParams {
  requestId: 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 {
  requestId: string;
}

export interface ExtensionLinkPayWaitDeleteRespone {
  status: boolean
}

// 분리승인 상세 조회 Request
export interface ExtensionLinkPaySeparateDetailParams {
  reqId: string;
}

// 분리승인 상세 조회 Response Item
export interface ExtensionLinkPaySeparateDetailItem {
  type: string;
  moid: string;
  amount: number;
  paymentStatus: string;
  paymentStatusName: string;
  paymentLimitDate: string;
  paymentLimitCount: number;
  requestId: string;
  subRequestId: string;
}

// 분리승인 상세 조회 Response
export interface ExtensionLinkPaySeparateDetailResponse {
  details: Array<ExtensionLinkPaySeparateDetailItem>;
}

export interface ExtensionLInkPaySeparateActionParams extends ExtensionRequestParams {
  action: string;
  reqId: string;
  selectedItems: Array<{
    type: string;
    subRequestId: string;
  }>;
  extendDate?: string;
}

export interface ExtensionLinkPaySeparateActionResponse {
  success : boolean;
  totalCount: number;
  successCount: number;
  failCount: number;
}