import { httpGet, httpPost, httpPut } from '../../utils/http'
import { Schedule } from '../models/schedule'
import {
  Content,
  DictType,
  MaterialDealer,
  MaterialDealerDetail,
  MaterialDealerHomePage,
  MaterialDealerRes,
  Moment,
} from '../models/moment'
import dayjs from 'dayjs'
import { getMaterialDealers } from '../../../../merchant/src/core/libs/requests'

export const getUserInfo = () =>
  httpGetMock<any>({
    avatar: 'https://via.placeholder.com/21x21',
    nickname: '苏小萌',
  })
export const getSchedule = () =>
  httpGetMock<Schedule>({
    name: '东京艺术设计研习营',
    cover: 'https://via.placeholder.com/375x297',
    items: [
      {
        title: '早稻田大学课程',
        time: '9:00',
        content:
          '是位于日本东京都新宿区的一所著名的私立大学。它由早稻田大学的创始人大隈重信于1882年创立，是日本超级国际化大学计划（Top Global University Project）选定的大学之一，也是日本顶尖的高等教育机构之一。',
        momentExample: 'https://via.placeholder.com/285x157',
        monentHint: '*说明：打卡地XX，收集上课素材',
      },
      {
        title: '早稻田大学博物馆参观',
        time: '11:00',
        content:
          '早稻田大学拥有多座博物馆，‌其中最著名的是早稻田大学历史馆。‌早稻田大学历史馆收藏、‌展示着著名校友在运动方面的杰出表现和成就，‌馆内的解说牌以日语和英语标示，‌展现了传统样式风格的建筑。',
        momentExample: 'https://via.placeholder.com/285x157',
        monentHint: '*说明：打卡地XX，收集上课素材',
      },
    ],
  })
export const getMoment = () =>
  httpGetMock<Moment>({
    author: {
      avatar: 'https://via.placeholder.com/35x35',
      nickname: '苏小萌',
      level: '0',
    },
    content: '用心做好设计，为客户创造美好家居环境',
    images: [
      'https://via.placeholder.com/165x220',
      'https://via.placeholder.com/220x220',
      'https://via.placeholder.com/165x220',
    ],
    tags: ['意大利游学设计班'],
    shares: 0,
    comments: 0,
    likes: 0,
    createdAt: dayjs('2024-07-15').toDate(),
    commentList: [],
  })
export const getClassmates = () =>
  httpGetMock<any[]>([
    {
      avatar: 'https://via.placeholder.com/35x35',
      nickname: '苏小萌',
      level: '0',
    },
    {
      avatar: 'https://via.placeholder.com/35x35',
      nickname: '苏小萌',
      level: '0',
    },
    {
      avatar: 'https://via.placeholder.com/35x35',
    },
  ])
export const getClassmate = () =>
  httpGetMock<any>({
    title: '2023同学荟|清华空间环境艺术设计研修班 阔步向未来',
    author: {
      avatar: 'https://via.placeholder.com/35x35',
      nickname: '苏小萌',
      level: '0',
    },
    viewNum: 125,
    createdAt: dayjs('2024-07-15').toDate(),
    content: '<div>111111</div>',
  })
export const getStudyTours = () =>
  httpGetMock<any[]>([
    {
      title: '东京艺术大学设计游学',
      createdAt: dayjs('2024-07-15').toDate(),
      startedAt: dayjs('2024-07-15').toDate(),
      endedAt: dayjs('2024-08-15').toDate(),
      amount: 16000,
    },
  ])
export const getMaterialDealers = () =>
  httpGetMock<any[]>([
    {
      name: 'IMOLA瓷砖',
      icon: 'https://via.placeholder.com/78x78',
      brandType: '进口品牌',
      type: '瓷砖',
      views: 1000,
      createdAt: dayjs('2024-07-15').toDate(),
    },
    {
      name: 'IMOLA瓷砖',
      icon: 'https://via.placeholder.com/78x78',
      brandType: '进口品牌',
      type: '瓷砖',
      views: 1000,
      createdAt: dayjs('2024-07-15').toDate(),
    },
  ])
export const weixinMiniAppLogin = (phoneCode: string, loginCode: string, state: string) =>
  httpPost<any>('/app-api/member/auth/weixin-mini-app-login', {
    phoneCode,
    loginCode,
    state,
  })
export const getMemberUserInfo = () => httpGet<any>('/app-api/member/user/get')
export const updateMemberUserInfo = (data = {}) => httpPut<any>('/app-api/member/user/update', data)
export const getByDictType = (
  type: string | 'member_channel_source' | 'member_spatial_expertise_type' | DictType,
) =>
  httpGet<
    {
      label: string
      value: string
      dictType: string
      status: number
    }[]
  >('/app-api/system/dict-data/type', { type })
export const createUserAuthInfo = (
  data: Partial<{
    id: number
    userId: number
    designerName: string
    gender: number
    mobile: string
    channelSource: number
    referrer: string
    employer: string
    spatialExpertiseType: number
    attachment: string
    auditStatus: number
    remark: string
  }>,
) => httpPost<any>('/app-api/member/user-auth-info/create', data)
export const getCircles = (query) =>
  httpGet<{
    list: {
      id: number
      headUrl?: string
      stylistId?: number
      stylistName?: string
      marketing?: string
      circleDesc?: string
      tagName?: string
      detailsType?: string
      detailsUrl?: string
      detailsDesc?: string
      circleType?: string
      spaceType?: string
      designStyle?: string
      spaceAddr?: string
      customerDemand?: string
      createTime: number
      bannerUrls: string[]
      shareCount?: number
      upvoteCount?: number
      ownUpvote: boolean
      reviewCount: number
    }[]
  }>('/app-api/member/circle/page', query)
export const createCircle = (data: Partial<Circle>) =>
  httpPost<any>('/app-api/member/circle/create', data)
export const getCircle = (id: string) =>
  httpGet<Partial<CircleRes>>('/app-api/member/circle/get', { id })
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 createCircleReview = (
  data: Partial<{
    circleId: string
    userId: string | number
    userName: string
    reviewContent: string
    replayReviewId: string
  }>,
) => httpPost<any>('/app-api/member/circle-review/create', data)
export const getCircleReviews = (query: { circleId: string }) =>
  httpGet<{
    list: Partial<{
      id: number
      circleId: number
      userId: number
      userName: string
      reviewContent: string
      upvoteCount: any
      replayReviewId: any
      reviewTime: number
      createTime: number
      replayToUserName: any
      replayToUserId: any
      replayFirstId: any
      upvote: boolean
      ownDel: boolean
    }>[]
  }>('/app-api/member/circle-review/getCircleReviewByCircleId', query)
export const createCircleReviewUpvote = (data: {
  circleId: number
  userId: number
  userName: string
  reviewId: number
}) => httpPost('/app-api/member/circle-review-upvote/create', data)
export const cancelCircleReviewUpvote = (query: {
  circleId: string
  userId: string
  reviewId: string
}) => httpGet('/app-api/member/circle-review-upvote/cancel', query)
export const getCircleReviewUpvotes = (query: { circleId: string; reviewId?: string }) =>
  httpGet('/app-api/member/circle-review-upvote/page', query)
export const getReviewReplay = (query: { id: string }) =>
  httpGet('/app-api/member/circle-review/getReviewReplay', query)
export const getTasks = (query) =>
  httpGet<{
    list: {
      id: number
      taskKey: string
      taskValue: string
      createTime: string
      sort: number
      status: number
    }[]
  }>('/app-api/basicsetting/set-task-center/page', query)
export const getCircleTags = (query) =>
  httpGet<{
    list: {
      id: number
      labelName: string
      labelType: number
      usageCount: number
      creator: string
      createTime: number
    }[]
  }>('/app-api/basicsetting/set-label/page', query)
export const getSetIndexConfigs = (query = {}) =>
  httpGet<{
    list: {
      id: number
      name: string
      indexPromotionalVideoImage: string
      coverVideoImage: string
      sort: number
      playCount: number
      status: number
      createTime: string
    }[]
  }>('/app-api/basicsetting/set-index-config/page', query)

/**
 * 获取材料商列表
 * @param query {{brandLevel: '1'|'2'}}
 * @returns {Promise<*>}
 */
export const getMaterials = (query = {}) =>
  httpGet<{
    list: MaterialDealer[]
  }>('/app-api/member/materials/page', query)
export const getAppMaterials = () =>
  httpGet<MaterialDealerRes[]>('/app-api/member/materials/appMaterialsList')
export const getAppMaterial = (id: number) =>
  httpGet<MaterialDealerDetail>('/app-api/member/materials/queryHomePage', { materialsId: id })
export const getMaterialHomePage = (id: number) =>
  httpGet<Partial<MaterialDealerHomePage>>('/app-api/member/materials/queryHomePage', {
    materialsId: id,
  })
export const getMaterialDetail = (query: { id: string }) =>
  httpGet<MaterialDealerDetail>('/app-api/member/materials/getDetail', query)
export const createMaterialsReferrer = (data) =>
  httpPost('/app-api/member/materials-referrer/create', data)
export const getContents = (query: {
  contentType: 'desin_learn' | 'offline_activity' | 'desin_communication'
  contentCategory?: string
}) => httpGet<{ list: Content[] }>('/app-api/member/content-manger/page', query)
export const getAllCategories = () => httpGet('/app-api/member/categories/getAllCategories')
export const getContent = (query: { id: string }) =>
  httpGet<Content>('/app-api/member/content-manger/get', query)
export const refreshToken = (refreshToken: string) =>
  httpPost<any>('/app-api/member/auth/refresh-token', {}, { refreshToken })
export const httpGetMock = <T>(data: T) =>
  new Promise<IResData<T>>((resolve) => resolve({ code: 1, msg: '', data } as IResData<T>))
export interface Circle {
  headUrl: string
  stylistId: string | number
  stylistName: string
  marketing: string
  circleDesc: string
  tagName: string
  detailsType: string
  detailsUrl: string
  detailsDesc: string
  circleType: string
  spaceType: string
  designStyle: string
  spaceAddr: string
  customerDemand: string
  bannerUrls: string[]
}
export interface CircleRes {
  id: number
  headUrl?: string
  stylistId?: number
  stylistName?: string
  marketing?: string
  circleDesc?: string
  tagName?: string
  detailsType?: string
  detailsUrl?: string
  detailsDesc?: string
  circleType?: string
  spaceType?: string
  designStyle?: string
  spaceAddr?: string
  customerDemand?: string
  createTime: number
  bannerUrls: string[]
  shareCount?: number
  upvoteCount?: number
  ownUpvote: boolean
  reviewCount: number
}
