import recordAxiosInstance from "@/shared/services/recordAxiosInstance";
import { withHeaders } from "./withHeaders";

interface IncomingStatusCounts {
  draft?: number;
  accepted?: number;
  rejected?: number;
  replied?: number;
  re_assigned?: number;
  urgent?: {
    draft?: number;
    accepted?: number;
    rejected?: number;
    replied?: number;
  };
}

interface IncomingStatusByRecordType {
  internal?: IncomingStatusCounts;
  internal_memo?: IncomingStatusCounts;
  direct?: IncomingStatusCounts;
  non_smart_user?: IncomingStatusCounts;
  external_non_smart_user?: IncomingStatusCounts;
  external?: IncomingStatusCounts;
  for_your_reference?: IncomingStatusCounts;
  cc?: IncomingStatusCounts;
}

export interface Report {
  activeApprovalCount?: {
    myNotUrgentWorkflowsCount?: number;
    myUrgentWorkflowCount?: number;
  };
  outgoingRecordStatusCount?: {
    Approved?: number;
    "Team Signature"?: number;
    Dispatched?: number;
    "Team Rejected"?: number;
    Submitted?: number;
    Adjustment?: number;
    Rejected?: number;
    Draft?: number;
  };
  collaborationCount?: {
    signed?: number;
    draft?: number;
    rejected?: number;
  };
  incomingStatusCountByEmployee?: IncomingStatusByRecordType;
  incomingStatusCountByPosition?: IncomingStatusByRecordType;
  incomingCCCounts?: {
    Unseen?: number;
    Seen?: number;
  };
  ccStatusCounts?: {
    ccCount?: number;
  };
  forYourReferenceCCStatusCounts?: {
    forYourReferenceCount?: number;
  };
}
export interface ReportIncoming {
  status: string;
  count: number;
}
export interface ReportRO {
  recordCount?: {
    external?: {
      assigned?: number;
      not_assigned?: number;
    };
    internal?: {
      assigned?: number;
      not_assigned?: number;
    };
    internal_memo?: {
      assigned?: number;
      not_assigned?: number;
    };
    non_smart_user?: {
      assigned?: number;
      not_assigned?: number;
    };
    external_non_smart_user?: {
      assigned?: number;
      not_assigned?: number;
    };
  };
  recordBoxCount?: {
    assigned?: number;
    not_assigned?: number;
    draft?: number;
  };
  outgoingInstanceCount?: {
    Adjustment?: number;
    Approved?: number;
    Dispatched?: number;
    Draft?: number;
    Submitted?: number;
    "Team Rejected"?: number;
    "Team Signature"?: number;
    urgent?: {
      Adjustment?: number;
      Approved?: number;
      Dispatched?: number;
      Draft?: number;
      Submitted?: number;
      "Team Rejected"?: number;
      "Team Signature"?: number;
    };
  };
}
export const getReport = async (): Promise<Report> => {
  const response = await recordAxiosInstance.get("/report/dashboard", {
    headers: withHeaders(),
  });

  return response.data;
};
export const getReportRO = async (params?: any): Promise<ReportRO> => {
  const response = await recordAxiosInstance.get("/report/ro-dashboard", {
    params,
    headers: withHeaders(),
  });

  return response.data;
};
export const getIncomingReport = async (
  id: string,
): Promise<ReportIncoming[]> => {
  const response = await recordAxiosInstance.get(
    `/incoming-instances/record-status-report/${id}`,
  );
  return response.data;
};
