import request from './request'

export interface MemberCard {
  memberCardId: number
  memberCardName: string
  memberCardType: string
  memberCardPrice: number
  memberCardValidityDays: number | null
  memberCardTotalTimes: number | null
  memberCardAmount: number | null
  memberCardStatus: number
  extraConfig: string | null
  createdAt: string
  updatedAt: string
}

export interface CreateMemberCardDto {
  memberCardName: string
  memberCardType: string
  memberCardPrice: number
  memberCardValidityDays?: number
  memberCardTotalTimes?: number
  memberCardAmount?: number
  memberCardStatus?: number
  extraConfig?: string
}

export interface UpdateMemberCardDto {
  memberCardName?: string
  memberCardType?: string
  memberCardPrice?: number
  memberCardValidityDays?: number
  memberCardTotalTimes?: number
  memberCardAmount?: number
  memberCardStatus?: number
  extraConfig?: string
}

export interface MemberCardQuery {
  status?: number
  name?: string
  type?: string
  minPrice?: number
  maxPrice?: number
  page?: number
  size?: number
}

/**
 * 分页查询会员卡类型列表
 */
export function listMemberCards(query: MemberCardQuery): Promise<MemberCard[]> {
  return request.get('/api/member-cards', { params: query })
}

/**
 * 查询上架的会员卡类型
 */
export function getActiveCards(status: number = 1): Promise<MemberCard[]> {
  return request.get('/api/member-cards/active', { params: { status } })
}

/**
 * 查询会员卡类型详情
 */
export function getMemberCardById(id: number): Promise<MemberCard> {
  return request.get(`/api/member-cards/${id}`)
}

/**
 * 创建会员卡类型
 */
export function createMemberCard(data: CreateMemberCardDto): Promise<MemberCard> {
  return request.post('/api/member-cards', data)
}

/**
 * 更新会员卡类型
 */
export function updateMemberCard(id: number, data: UpdateMemberCardDto): Promise<MemberCard> {
  return request.put(`/api/member-cards/${id}`, data)
}

/**
 * 删除会员卡类型（逻辑删除）
 */
export function deleteMemberCard(id: number): Promise<void> {
  return request.delete(`/api/member-cards/${id}`)
}
