import { http } from "@/utils/http";

type Result = {
  code: number;
  message: string;
  data?: any;
};

type ResultTable = {
  code: number;
  message: string;
  data?: {
    list: Array<any>;
    total: number;
    pageSize: number;
    currentPage: number;
  };
};

export const submitCheckin = (data: {
  type: string;
  shopId?: number;
  deviceId?: string;
  location: {
    latitude: number;
    longitude: number;
    address: string;
    accuracy?: number;
  };
  photos: Array<{
    id?: string;
    path: string;
    watermarkPath?: string;
    timestamp?: number;
  }>;
  remark?: string;
  offlineId?: string;
}) => {
  return http.request<Result>("post", "/checkin", { data });
};

export const getCheckinList = (params: {
  page?: number;
  pageSize?: number;
  type?: string;
  userId?: number;
  shopId?: number;
  startDate?: string;
  endDate?: string;
  status?: string;
}) => {
  return http.request<ResultTable>("get", "/checkin", { params });
};

export const getCheckinDetail = (id: number) => {
  return http.request<Result>("get", `/checkin/${id}`);
};

export const getCheckinStats = () => {
  return http.request<Result>("get", "/checkin/stats");
};

export const getTodayCheckin = () => {
  return http.request<Result>("get", "/checkin/today");
};

export const syncOfflineCheckins = (data: { records: any[] }) => {
  return http.request<Result>("post", "/checkin/sync", { data });
};

export const exportCheckinRecords = (params: {
  type?: string;
  userId?: number;
  shopId?: number;
  startDate?: string;
  endDate?: string;
  status?: string;
}) => {
  return http.request<Result>("get", "/checkin/export", { params });
};
