import http from '@/utils/request'

// 获取票种列表
export function getTicketType (params) {
  // eslint-disable-next-line prefer-const
  let { pageNum = 1, pageSize = 10, channel, is_reservation, scenic, type, status = ['inactive', 'active'] } = params

  status = status.map(val => {
    return `status=${val}`
  }).join('&')

  return http.get(`tickettype/?${channel ? `channel=${channel}` : ''}&${type ? `type=${type}` : ''}&${(pageNum === 0 || pageNum) ? `pageNum=${pageNum}` : ''}&${(pageSize === 0 || pageSize) ? `pageSize=${pageSize}` : ''}&${scenic ? `scenic=${scenic}` : ''}&${is_reservation ? 'is_reservation=1' : 'is_reservation=0'}&${status}`)
}

export function getTicketTypeWithIds (params) {
  // eslint-disable-next-line prefer-const
  let { pageNum = 1, pageSize = 10, is_reservation, scenic, type, status = ['inactive', 'active'] } = params
  const { scenic_ids, channel_ids } = params
  status = status.map(val => {
    return `status=${val}`
  }).join('&')
  // 支持多个景点
  const scenicIdsStr = scenic_ids?.map(val => {
    return `scenic_ids=${val}`
  }).join('&')
  // 支持多个渠道
  const channelIdsStr = channel_ids?.map(val => {
    return `channel_ids=${val}`
  }).join('&')
  const finalStr = `tickettype/?${channelIdsStr}&${scenicIdsStr}&${type ? `type=${type}` : ''}&${(pageNum === 0 || pageNum) ? `pageNum=${pageNum}` : ''}&${(pageSize === 0 || pageSize) ? `pageSize=${pageSize}` : ''}&${scenic ? `scenic=${scenic}` : ''}&${is_reservation ? 'is_reservation=1' : 'is_reservation=0'}&${status}`
  return http.get(finalStr)
}

export function getTicketTypeById (id) {
  return http.get(`tickettype/${id}`)
}

export function setTicketTypeById (id, params) {
  return http.put(`tickettype/${id}`, params)
}

// 删除票种
export function deleteTicketTypeById (id) {
  return http.delete(`tickettype/${id}`)
}

// 新增票种列表
export function addTicketType (params) {
  return http.post('tickettype/', params)
}

// 获取票种标签
export function getTicketTag (params) {
  const { pageNum = 1, pageSize = 999 } = params
  return http.get(`tickettypetag/?pageNum=${pageNum}&pageSize=${pageSize}`)
}

// 新增票种标签
export function addTicketTag (params) {
  return http.post('tickettypetag/', params)
}

// 编辑票种标签
export function setTicketTag (id, params) {
  return http.put(`tickettypetag/${id}`, params)
}

// 删除票种标签
export function deleteTicketTag (id) {
  return http.delete(`tickettypetag/${id}`)
}

// 获取价格码
export function getTicketProduct (params) {
  const { pageNum = 1, pageSize = 999 } = params
  return http.get(`ticketproduct/?pageNum=${pageNum}&pageSize=${pageSize}`)
}

// 获取门票景点
export function getTicketScenic (id) {
  return http.get(`tickettype/${id}/scenics`)
}

// 获取座位类型列表
export function getSeatTypeList (params) {
  // eslint-disable-next-line prefer-const
  let { id, status = ['inactive', 'active'] } = params

  status = status.map(val => {
    return `status=${val}`
  }).join('&')

  return http.get(`batchtype/${id}/seattype?${status}`)
}

// 设置门票景点
export function setTicketScenic (id, params) {
  return http.post(`tickettype/${id}/scenics`, params)
}

// 获取门票渠道
export function getTicketChannel (id) {
  return http.get(`tickettype/${id}/channels`)
}

// 设置门票渠道
export function setTicketChannel (id, params) {
  return http.post(`tickettype/${id}/channel`, params)
}

// 设置激活门票
export function setTicketActive (id, bool) {
  const params = {
    active: bool
  }
  return http.post(`tickettype/${id}/active`, params)
}

// 获取日期段价格
export function getPeriodPrice (id) {
  return http.get(`tickettype/${id}/periodprice`)
}

// 设置日期段价格
export function setPeriodPrice (id, params) {
  return http.post(`tickettype/${id}/periodprice`, params)
}

// 获取周价格
export function getWeekDayPrice (id) {
  return http.get(`tickettype/${id}/weekdayprice`)
}

// 设置周价格
export function setWeekDayPrice (id, params) {
  return http.post(`tickettype/${id}/weekdayprice`, params)
}

// 当前票价策略
export function getTicketPriceStragegy () {
  return http.get('config/ticketpricestrategy')
}

// 当前票价策略
export function updateseq (params) {
  return http.post('/tickettype/updateseq', params)
}

/* ------------------------------------场次票------------------------------------------- */
export function getTicketBatch (id) {
  return http.get(`/tickettype/${id}/batch`)
}

export function setTicketBatch (id, batches) {
  return http.post(`/tickettype/${id}/batch`, { batches })
}
// 设置售卖信息
export function setSalesInfo (params) {
  return http.post(`/product/salesinfo`, params)
}

// 设置绑定场次
export function getBatch (params) {
  // eslint-disable-next-line prefer-const
  let { status = ['inactive', 'active'], ticket_type_id } = params

  status = status.map(val => {
    return `status=${val}`
  }).join('&')

  return http.get(`product/batch?${status}&ticket_type_id=${ticket_type_id}`)
}

// 删除售卖信息
export function deleteSalesInfo (params) {
  return http.delete(`/product/salesinfo`, params)
}

// 获取售卖信息
export function getSalesInfo (params) {
  return http.get(`/product/salesinfo`, params)
}

export function getTicketBatchPrice (id) {
  return http.get(`/tickettype/${id}/batchprice`)
}

export function setTicketBatchPrice (id, batches) {
  return http.post(`/tickettype/${id}/batchprice`, { batches })
}

// 意见反馈
export function comments (params) {
  const { pageNum = 1, pageSize = 10 } = params
  return http.get(`commentsFeedback/comments/?pageNum=${pageNum}&pageSize=${pageSize}`)
}
