import { httpGet, httpPost, httpPut, httpDelete } from '@/utils/http'
import {
  PointsOrder,
  ResPageData,
  Todo,
  Agent,
  AgentTask,
} from '@designer-hub/app/src/core/libs/models'
import {AgreementType} from "@/core/libs/enums";

export const httpGetMock = <T>(data: T) =>
  new Promise<IResData<T>>((resolve) => resolve({ code: 1, msg: '', data } as IResData<T>))
export const createCircleUpvote = (data: { circleId: number; userId: number; userName: string }) =>
  httpPost('/app-api/member/circle-upvote/create', data)
export const cancelCircleUpvote = (query: { id: string }) =>
  httpGet('/app-apimember/circle-upvote/delete', query)
export const cancelCircleReviewUpvote = (query: {
  circleId: string
  userId: string
  reviewId: string
}) => httpGet('/app-api/member/circle-review-upvote/cancel', query)
// 获取设计师列表
export const getDesignerList = (query: { brokerId: string; pageNo: number; pageSize: any }) =>
  httpGet<ResPageData<any>>('/app-api/member/report-info/pageStylistByBrokerId', query)
// 添加关系报备
export const createReportInfo = (data: any) =>
  httpPost<any>('/app-api/member/report-info/create', data)
// 获取任务列表
export const getTaskList = (query: any) => httpGet<any>('/app-api/member/task/task-list', query)
// 任务详情
export const getTaskDetail = (query = {}) =>
  httpGet<AgentTask>('/app-api/member/task/task-detail', query)
// 领取任务
export const taskReceive = (data: any) => httpPost<any>('/app-api/member/task/task-receive', data)
// 任务上报
export const appTaskReport = (data: any) =>
  httpPost<any>('/app-api/member/app-task-report/create', data)
export const login = (data: {
  mobile: string
  password: string
  socialType: number
  socialCode: string
  socialState: string
  socialCodeValid: boolean
}) =>
  httpPost<{
    userId: number
    accessToken: string
    refreshToken: string
    expiresTime: number
    appLoginType: number
    openid: any
  }>('/app-api/member/auth/login', data)
export const refreshToken = (refreshToken: string) =>
  httpPost<any>('/app-api/member/auth/refresh-token', {}, { refreshToken })
/**
 * 商家端-扫码验券
 */
export const scanCodeCheckPaper = (data: { orderNo: string }) =>
  httpPost('/app-api/member/vendorApp/scanCodeCheckPaper', data)
/**
 * 商家端-获取商家信息
 */
export const getVendorAppInfo = () =>
  httpGet<{
    id: number
    avatar: string
    vendorName: string
    contactName: string
    password: string
    mobile: string
    status: number
    createTime: number
    orderCount: any
    totalPoints: any
    level: number
  }>('/app-api/member/vendorApp/getInfo')
/**
 * 商家端-获取商家订单
 */
export const getOrders = () =>
  httpPost<
    ResPageData<{
      id: number
      orderType: number
      item?: number
      materialsId: any
      materialsBrand: any
      stylistId: number
      orderMoney: any
      projectName: string
      pointsRate: any
      points: string
      orderImgUrl?: string
      orderStatus: string
      verifyTime: any
      completeTime?: number
      turnDownTime: any
      cancelTime?: number
      cancelReason: any
      turnDownReason: any
      remark: any
      couponId: any
      orderNo: string
      createTime: number
      brokerageRate: any
      brokerage: any
      orderQuantity: number
      payType?: number
      payPoints?: number
    }>
  >('/app-api/member/vendorApp/getPointsOrderByVendorPage')
/**
 * 商家端-获取订单详情
 */
export const getPointsOrder = (id: any) =>
  httpGet<Partial<PointsOrder>>('/app-api/member/points-order/get', { id })
/**
 * 渠道端-获取待办列表
 */
export const getTodos = (query: { brokerId: string; executionTime: string }) =>
  httpGet<Todo[]>('/app-api/member/todo/list', query)
/**
 * 渠道端-获取待办分页
 */
export const getTodoPage = (query: { pageNo: number; pageSize: number }) =>
  httpGet<ResPageData<Todo>>('/app-api/member/todo/page', query)
/**
 * 渠道端-创建待办
 */
export const createTodo = (data: Partial<Todo>) => httpPost('/app-api/member/todo/create', data)
/**
 * 渠道端-删除待办
 */
export const deleteTodo = (id: number) => httpDelete('/app-api/member/todo/delete', { id })
/**
 * 渠道端-更新待办
 */
export const updateTodo = (data: Partial<Todo>) =>
  httpPut('/app-api/member/todo/updateStatus', data)
/**
 * 渠道端-获取设计师活动列表
 */
export const getDesignerPointsActivities = (query: { brokerId: string }) =>
  httpGet<
    ResPageData<{
      content: string
      createTime: number
    }>
  >('/app-api/member/points-order/getPointsDynamics', query)
/**
 * 渠道端-获取本年目标
 */
export const getYearTarget = (query?: { brokerId?: string }) =>
  httpPost<
    {
      id: any
      brokerId: any
      type: number
      typeName: string
      year: any
      target: any
      thisYearComplete?: number
      thisMonthComplete?: number
      remark: any
    }[]
  >('/app-api/member/app-broker/statisticsThisYearTask')
/**
 * 渠道端-获取设计师统计
 */
export const getDesignerStatistics = (query = {}) =>
  httpPost<any>('/app-api/member/app-broker/statisticsStylist', query)
/**
 * 渠道端-获取跟进统计
 */
export const getFollowStatistics = (query = {}) =>
  httpPost<{ type: number; typeName: string; quantity?: number; thisYearQuantity?: number }[]>(
    '/app-api/member/app-broker/statisticsFollowUp',
    query,
  )
/**
 * 渠道端-获取经纪人
 */
export const getBroker = (query: { brokerId: string }) =>
  httpGet<Agent>('/app-api/member/app-broker/get', query)
/**
 * 获取会员等级配置
 */
export const getAppMemberLevelConfigs = () =>
  httpGet<
    {
      id: number
      memberLevel: number
      memberLevelName: string
      upgradeCriteria: number
      points: number
      retentionDaysCriteria: number
      retentionDays: number
      memberBgImage: string
      associatedMemberRights: string
      associatedMemberRightsName: string
      status: number
      createTime: string
      logo: string
      setMemberRights: {
        createTime: string
        updateTime: string
        creator: string
        updater: string
        deleted: boolean
        id: number
        rightsName: string
        rightsType: number
        rightsImage: string
        rightsDescription: string
        associatedMemberRightsLevel: string
        status: number
      }[]
    }[]
  >('/app-api/basicsetting/app-set-member-level-config/listAndRights')
export interface UpdatePasswordData {
  id: number
  oldPassword?: string
  newPassword?: string
  appLoginType: AppLoginType
}
/**
 * 修改密码
 */
export const updatePassword = (data: UpdatePasswordData) =>
  httpPut('/app-api/member/auth/update-password', data)
export const fakeThis = (query: { agreement: AgreementType }) =>
  httpGet<string>('/app-api/infra/file/download', query)
