/**
 * 团课模拟数据（测试环境使用）
 * 数据格式与后端返回格式保持一致
 */

// 模拟团课列表数据（与后端返回格式一致）
const mockCourseList = [
  {
    "id": "1",
    "createBy": "admin",
    "updateBy": null,
    "createdAt": "2026-06-01T11:00:00",
    "updatedAt": "2026-06-01T11:00:00",
    "deletedAt": null,
    "courseName": "极速燃脂单车",
    "coachId": "104",
    "courseType": "2",
    "startTime": "2026-06-02T16:45:00",
    "endTime": "2026-06-15T20:20:00",
    "maxMembers": 25,
    "currentMembers": 0,
    "status": "0",
    "location": "单车房",
    "coverImage": "https://picsum.photos/seed/spinning/640/360",
    "description": "跟随音乐节奏变换阻力和速度，体验爬坡与冲刺的快感，一节课消耗800大卡。支持次数卡(1次)或储值卡(50元)支付。",
    "pointCardAmount": 0,
    "storedValueAmount": 0
  },
  {
    "id": "3",
    "createBy": "coach_zhang",
    "updateBy": null,
    "createdAt": "2026-06-01T14:30:00",
    "updatedAt": "2026-06-01T14:30:00",
    "deletedAt": null,
    "courseName": "燃脂搏击",
    "coachId": "102",
    "courseType": "2",
    "startTime": "2026-06-10T18:30:00",
    "endTime": "2026-06-10T19:30:00",
    "maxMembers": 20,
    "currentMembers": 20,
    "status": "0",
    "location": "综合训练区",
    "coverImage": "https://picsum.photos/seed/kickboxing/640/360",
    "description": "高强度间歇训练，配合音乐快速燃脂，释放压力。名额已满，无法预约。支持次数卡(1次)或储值卡(60元)支付。",
    "pointCardAmount": 1,
    "storedValueAmount": 60
  },
  {
    "id": "4",
    "createBy": "coach_li",
    "updateBy": null,
    "createdAt": "2026-06-01T08:00:00",
    "updatedAt": "2026-06-01T08:00:00",
    "deletedAt": null,
    "courseName": "哈他瑜伽",
    "coachId": "101",
    "courseType": "1",
    "startTime": "2026-06-01T15:20:00",
    "endTime": "2026-06-01T16:50:00",
    "maxMembers": 12,
    "currentMembers": 3,
    "status": "0",
    "location": "瑜伽教室B",
    "coverImage": "https://picsum.photos/seed/yoga/640/360",
    "description": "基础哈他瑜伽，适合所有级别。距开始不足30分钟，已停止预约。支持次数卡(1次)或储值卡(40元)支付。",
    "pointCardAmount": 1,
    "storedValueAmount": 40
  },
  {
    "id": "5",
    "createBy": "coach_wang",
    "updateBy": null,
    "createdAt": "2026-05-28T08:00:00",
    "updatedAt": "2026-05-28T08:00:00",
    "deletedAt": null,
    "courseName": "周末冥想修复",
    "coachId": "101",
    "courseType": "1",
    "startTime": "2026-06-20T15:00:00",
    "endTime": "2026-06-20T16:00:00",
    "maxMembers": 12,
    "currentMembers": 3,
    "status": "1",
    "location": "冥想室",
    "coverImage": "https://picsum.photos/seed/meditation/640/360",
    "description": "通过呼吸和正念冥想，深度放松身心。该课程已被取消。支持次数卡(1次)或储值卡(30元)支付。",
    "pointCardAmount": 1,
    "storedValueAmount": 30
  },
  {
    "id": "6",
    "createBy": "coach_li",
    "updateBy": null,
    "createdAt": "2026-05-20T09:15:00",
    "updatedAt": "2026-05-20T09:15:00",
    "deletedAt": null,
    "courseName": "蜜桃臀塑造",
    "coachId": "103",
    "courseType": "3",
    "startTime": "2026-05-30T19:00:00",
    "endTime": "2026-05-30T20:00:00",
    "maxMembers": 10,
    "currentMembers": 8,
    "status": "2",
    "location": "私教专区",
    "coverImage": "https://picsum.photos/seed/glute/640/360",
    "description": "针对性训练臀部肌肉群，课程已于5月30日结束，无法预约。支持次数卡(1次)或储值卡(80元)支付。",
    "pointCardAmount": 1,
    "storedValueAmount": 80
  },
  {
    "id": "7",
    "createBy": "admin",
    "updateBy": null,
    "createdAt": "2026-05-25T09:00:00",
    "updatedAt": "2026-05-25T09:00:00",
    "deletedAt": null,
    "courseName": "午间冥想放松",
    "coachId": "101",
    "courseType": "1",
    "startTime": "2026-05-31T12:00:00",
    "endTime": "2026-05-31T13:00:00",
    "maxMembers": 15,
    "currentMembers": 6,
    "status": "2",
    "location": "冥想室",
    "coverImage": "https://picsum.photos/seed/noonmeditation/640/360",
    "description": "午间冥想课程，已于5月31日结束。支持次数卡(1次)或储值卡(25元)支付。",
    "pointCardAmount": 1,
    "storedValueAmount": 25
  },
  {
    "id": "8",
    "createBy": "admin",
    "updateBy": null,
    "createdAt": "2026-06-01T10:00:00",
    "updatedAt": "2026-06-01T10:00:00",
    "deletedAt": null,
    "courseName": "燃脂搏击_次数卡课程",
    "coachId": "102",
    "courseType": "2",
    "startTime": "2026-06-10T19:30:00",
    "endTime": "2026-06-10T20:30:00",
    "maxMembers": 20,
    "currentMembers": 0,
    "status": "0",
    "location": "综合训练区",
    "coverImage": null,
    "description": "高强度间歇训练，配合音乐快速燃脂，消耗1次",
    "pointCardAmount": 1,
    "storedValueAmount": 0
  },
  {
    "id": "9",
    "createBy": "admin",
    "updateBy": null,
    "createdAt": "2026-06-01T10:00:00",
    "updatedAt": "2026-06-01T10:00:00",
    "deletedAt": null,
    "courseName": "高端普拉提_储值卡课程",
    "coachId": "103",
    "courseType": "1",
    "startTime": "2026-06-11T19:00:00",
    "endTime": "2026-06-11T20:00:00",
    "maxMembers": 15,
    "currentMembers": 0,
    "status": "0",
    "location": "普拉提教室",
    "coverImage": null,
    "description": "精准训练核心肌群，消耗储值50元",
    "pointCardAmount": 0,
    "storedValueAmount": 20
  },
  {
    "id": "11",
    "createBy": "admin",
    "updateBy": null,
    "createdAt": "2026-06-02T10:00:00",
    "updatedAt": "2026-06-02T10:00:00",
    "deletedAt": null,
    "courseName": "时间冲突测试_A_13点-15点",
    "coachId": "102",
    "courseType": "2",
    "startTime": "2026-06-15T13:00:00",
    "endTime": "2026-06-15T15:00:00",
    "maxMembers": 20,
    "currentMembers": 0,
    "status": "0",
    "location": "综合训练区",
    "coverImage": null,
    "description": "测试用团课A，用于验证时间冲突检测。支持次数卡(1次)或储值卡(50元)支付。",
    "pointCardAmount": 1,
    "storedValueAmount": 50
  },
  {
    "id": "12",
    "createBy": "admin",
    "updateBy": null,
    "createdAt": "2026-06-02T10:00:00",
    "updatedAt": "2026-06-02T10:00:00",
    "deletedAt": null,
    "courseName": "时间冲突测试_B_14点-16点",
    "coachId": "103",
    "courseType": "1",
    "startTime": "2026-06-15T14:00:00",
    "endTime": "2026-06-15T16:00:00",
    "maxMembers": 15,
    "currentMembers": 0,
    "status": "0",
    "location": "普拉提教室",
    "coverImage": null,
    "description": "测试用团课B，与团课A时间重叠（14:00-15:00）。支持次数卡(1次)或储值卡(50元)支付。",
    "pointCardAmount": 1,
    "storedValueAmount": 50
  },
  {
    "id": "13",
    "createBy": "admin",
    "updateBy": null,
    "createdAt": "2026-06-02T10:00:00",
    "updatedAt": "2026-06-02T10:00:00",
    "deletedAt": null,
    "courseName": "时间冲突测试_C_10点-12点",
    "coachId": "101",
    "courseType": "1",
    "startTime": "2026-06-15T10:00:00",
    "endTime": "2026-06-15T12:00:00",
    "maxMembers": 15,
    "currentMembers": 0,
    "status": "0",
    "location": "瑜伽教室",
    "coverImage": null,
    "description": "测试用团课C，与团课A/B不冲突。支持次数卡(1次)或储值卡(50元)支付。",
    "pointCardAmount": 1,
    "storedValueAmount": 50
  },
  {
    "id": "14",
    "createBy": "system",
    "updateBy": "system",
    "createdAt": "2026-06-02T17:32:50.532336",
    "updatedAt": "2026-06-02T17:32:50.532336",
    "deletedAt": null,
    "courseName": "动感单车aaa",
    "coachId": "2",
    "courseType": "2",
    "startTime": "2026-06-05T18:00:00",
    "endTime": "2026-06-05T19:00:00",
    "maxMembers": 25,
    "currentMembers": 0,
    "status": "0",
    "location": "健身房B区",
    "coverImage": "https://example.com/spinning.jpg",
    "description": "高强度有氧运动课程",
    "pointCardAmount": 1,
    "storedValueAmount": 50
  },
  {
    "id": "2",
    "createBy": "admin",
    "updateBy": null,
    "createdAt": "2026-06-01T10:00:00",
    "updatedAt": "2026-06-02T17:35:35.155616",
    "deletedAt": null,
    "courseName": "清晨流瑜伽",
    "coachId": "101",
    "courseType": "1",
    "startTime": "2026-06-12T09:00:00",
    "endTime": "2026-06-12T10:30:00",
    "maxMembers": 15,
    "currentMembers": 6,
    "status": "0",
    "location": "A座3楼瑜伽教室",
    "coverImage": "https://picsum.photos/seed/yogaflow/640/360",
    "description": "适合有一定基础的学员，通过流畅的体式连接呼吸，唤醒身体能量。支持次数卡(1次)或储值卡(45元)支付。",
    "pointCardAmount": 1,
    "storedValueAmount": 45
  },
  {
    "id": "15",
    "createBy": "system",
    "updateBy": "system",
    "createdAt": "2026-06-02T17:57:27.483488",
    "updatedAt": "2026-06-02T17:57:27.483488",
    "deletedAt": null,
    "courseName": "动感单车",
    "coachId": "2",
    "courseType": "2",
    "startTime": "2026-06-05T18:00:00",
    "endTime": "2026-06-05T19:00:00",
    "maxMembers": 25,
    "currentMembers": 0,
    "status": "0",
    "location": "健身房B区",
    "coverImage": "https://example.com/spinning.jpg",
    "description": "高强度有氧运动课程",
    "pointCardAmount": 1,
    "storedValueAmount": 50
  }
]

// 模拟团课类型标签数据
const mockCourseTypeLabels = [
  {
    "id": "1",
    "createBy": null,
    "updateBy": null,
    "createdAt": "2026-06-11T11:29:07.859339",
    "updatedAt": "2026-06-11T11:29:07.859339",
    "deletedAt": null,
    "labelName": "高级进阶",
    "color": "#f5222d",
    "description": "适合高级学员"
  },
  {
    "id": "2",
    "createBy": null,
    "updateBy": null,
    "createdAt": "2026-06-11T11:29:07.859339",
    "updatedAt": "2026-06-11T11:29:07.859339",
    "deletedAt": null,
    "labelName": "增肌强化",
    "color": "#13c2c2",
    "description": "有助于增肌强化"
  }
]

// 团课类型与标签的关联关系
const courseTypeLabelMap = {
  '1': [
    { id: '1', labelName: '高级进阶', color: '#f5222d' },
    { id: '2', labelName: '增肌强化', color: '#13c2c2' }
  ],
  '2': [
    { id: '3', labelName: '燃脂挑战', color: '#fa8c16' },
    { id: '4', labelName: 'HIIT高强度', color: '#722ed1' }
  ],
  '3': [
    { id: '5', labelName: '塑形美体', color: '#eb2f96' },
    { id: '6', labelName: '核心训练', color: '#52c41a' }
  ]
}

/**
 * 模拟团课API（测试环境）
 * 接口签名与真实API保持一致
 */
export const groupCourseMockApi = {
  /**
   * 获取团课列表（支持分页）
   * @param {Object} params - 查询参数
   * @param {number} params.pageNum - 页码（从1开始）
   * @param {number} params.pageSize - 每页数量
   * @returns {Promise} - 分页团课列表数据
   */
  getList: (params = {}) => {
    return new Promise((resolve) => {
      setTimeout(() => {
        const pageNum = params.pageNum || 1
        const pageSize = params.pageSize || 10
        
        const total = mockCourseList.length
        const startIndex = (pageNum - 1) * pageSize
        const endIndex = startIndex + pageSize
        const list = mockCourseList.slice(startIndex, endIndex)
        
        console.log('[groupCourse.mock.js] 模拟获取团课列表（分页）:', {
          pageNum,
          pageSize,
          total,
          listCount: list.length
        })
        
        resolve({
          code: 0,
          message: 'success',
          data: {
            list,
            total,
            pageNum,
            pageSize,
            totalPages: Math.ceil(total / pageSize)
          }
        })
      }, 500)
    })
  },
  
  /**
   * 获取团课详情
   * @param {string} id - 课程ID
   * @returns {Promise} - 团课详情数据
   */
  getDetail: (id) => {
    return new Promise((resolve, reject) => {
      setTimeout(() => {
        console.log('[groupCourse.mock.js] 模拟获取团课详情:', id)
        const course = mockCourseList.find(item => item.id === id)
        if (course) {
          resolve(course)
        } else {
          reject({ code: -1, message: '课程不存在' })
        }
      }, 300)
    })
  },
  
  /**
   * 预约团课
   * @param {Object} data - 预约数据
   * @param {string} data.courseId - 课程ID
   * @param {string} data.memberId - 会员ID
   * @returns {Promise} - 预约结果
   */
  book: (data) => {
    return new Promise((resolve) => {
      setTimeout(() => {
        console.log('[groupCourse.mock.js] 模拟预约团课:', data)
        resolve({
          code: 0,
          message: '预约成功',
          data: { bookingId: `BK${Date.now()}` }
        })
      }, 400)
    })
  },
  
  /**
   * 取消预约
   * @param {string} id - 预约记录ID
   * @returns {Promise} - 取消结果
   */
  cancelBooking: (id) => {
    return new Promise((resolve) => {
      setTimeout(() => {
        console.log('[groupCourse.mock.js] 模拟取消预约:', id)
        resolve({
          code: 0,
          message: '取消成功',
          data: null
        })
      }, 300)
    })
  },

  /**
   * 基于类型ID获取标签列表
   * @param {string} courseType - 团课类型ID
   * @returns {Promise} - 标签列表数据
   */
  getLabelsByCourseType: (courseType) => {
    return new Promise((resolve) => {
      setTimeout(() => {
        console.log('[groupCourse.mock.js] 模拟获取团课类型标签:', courseType)
        const labels = courseTypeLabelMap[courseType] || []
        resolve({
          code: 0,
          message: 'success',
          data: labels
        })
      }, 200)
    })
  }
}

export const groupCourseService = groupCourseMockApi

export default groupCourseMockApi
