import request from '@/utils/request';
import type { ApiResult, PageResult } from '@/api';
import type { UserPlanLog, UserPlanLogParam } from '@/api/love/plan-log/model';
/**
 * 分页查询日志
 */
export async function pageUserPlanLog(params: UserPlanLogParam) {
  const res = await request.get<ApiResult<PageResult<UserPlanLog>>>(
    '/love/user-plan-log/page',
    {
      params
    }
  );
  if (res.data.code === 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 查询日志列表
 */
export async function listUserPlanLog(params?: UserPlanLogParam) {
  const res = await request.get<ApiResult<UserPlanLog[]>>(
    '/love/user-plan-log',
    {
      params
    }
  );
  if (res.data.code === 0 && res.data.data) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 添加日志
 */
export async function addUserPlanLog(data: UserPlanLog) {
  const res = await request.post<ApiResult<unknown>>(
    '/love/user-plan-log',
    data
  );
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 修改日志
 */
export async function updateUserPlanLog(data: UserPlanLog) {
  const res = await request.put<ApiResult<unknown>>(
    '/love/user-plan-log',
    data
  );
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 绑定日志
 */
export async function bindUserPlanLog(data: UserPlanLog) {
  const res = await request.put<ApiResult<unknown>>(
    '/love/user-plan-log/bind',
    data
  );
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 批量添加
 */
export async function addBatchUserPlanLog(data: UserPlanLog[]) {
  const res = await request.post<ApiResult<unknown>>(
    '/love/user-plan-log/batch',
    data
  );
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 删除日志
 */
export async function removeUserPlanLog(id?: number) {
  const res = await request.delete<ApiResult<unknown>>(
    '/love/user-plan-log/' + id
  );
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 批量删除日志
 */
export async function removeBatchUserPlanLog(data: (number | undefined)[]) {
  const res = await request.delete<ApiResult<unknown>>(
    '/love/user-plan-log/batch',
    {
      data
    }
  );
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}
