import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
  Query,
} from '@nestjs/common';
import { OnlineCourseService } from '../service/online-course.service';
import { CreateOnlineCourseDto } from '../dto/course-manage/create-online-course.dto';
import { UpdateOnlineCourseDto } from '../dto/course-manage/update-online-course.dto';
import { CreateCourseclassifyDto } from '../dto/course-manage/course-classify.dto';
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
import { updateCourseclassifyDto } from '../dto/course-manage/update-course-classify.dto';
import { updateCourseStatuDto } from '../dto/course-manage/update-online-course.dto';
import { NoAuthToken } from 'src/common/decorator/no-token.decorator';
import { PaginationDTO } from '../common/pagination.dto';
import { DeleteDto } from '../common//delete-dto';
import {
  getCourseClassifyLsitDto,
  SearchLsitDto,
} from '../dto/course-manage/get-course-list-dto';
import { TokenData } from 'src/common/decorator/token-data.decorator';

@ApiTags('在线课程')
@ApiBearerAuth()
@Controller('online-course')
export class OnlineCourseController {
  constructor(private readonly onlineCourseService: OnlineCourseService) {}
  // 新建课程
  @Post()
  @ApiOperation({ summary: '新建课程' })
  create(@Body() createOnlineCourseDto: CreateOnlineCourseDto) {
    return this.onlineCourseService.create(createOnlineCourseDto);
  }
  // 获取课程列表
  @Get('course')
  @ApiOperation({ summary: '获取课程列表' })
  findAll(
    @Query() getInfoDTO: getCourseClassifyLsitDto,
    @TokenData() tokenInfo: any,
  ) {
    return this.onlineCourseService.findAll(getInfoDTO, tokenInfo);
  }
  // 获取课程列表
  @Get('course-evaluate/:courseId')
  @ApiOperation({ summary: '获取课程列表' })
  async findEvaluate(
    @Param('courseId') courseId: number,
    @Query() paging: PaginationDTO,
  ) {
    const datas = await this.onlineCourseService.getCourseEvaluate(
      +courseId,
      paging,
    );
    datas.data = datas.data.map((item) => {
      return {
        ...item,
        value: JSON.parse(item.value),
      };
    });
    return datas;
  }
  // 搜索课程列表
  @Get('course_search')
  @ApiOperation({ summary: '搜索课程列表' })
  searchCourseLsit(
    @Query() searchInfo: SearchLsitDto,
    @TokenData() tokenInfo: any,
  ) {
    return this.onlineCourseService.searchCourseList(searchInfo, tokenInfo);
  }

  @Get('course/:id')
  @ApiOperation({ summary: '查询具体某个课程' })
  findOne(@Param('id') id: string) {
    return this.onlineCourseService.findOne(+id);
  }
  // 编辑课程-整体编辑
  @Patch('course/:id')
  @ApiOperation({ summary: '更新某个课程' })
  update(
    @Param('id') id: string,
    @Body() updateOnlineCourseDto: UpdateOnlineCourseDto,
  ) {
    return this.onlineCourseService.update(+id, updateOnlineCourseDto);
  }
  // 编辑课程-状态信息等编辑
  @Get('course_status/:id')
  @ApiOperation({ summary: '更新某个课程状态' })
  updateStatus(@Param('id') id: string, @Query() data: updateCourseStatuDto) {
    return this.onlineCourseService.updateStatus(+id, data);
  }
  // 删除课程
  @Post('batch_delete')
  @ApiOperation({ summary: '删除课程' })
  batchDeleteCourse(@Body() data: DeleteDto) {
    this.onlineCourseService.batchDeleteCourse(data);
  }

  @Delete('course/:id')
  remove(@Param('id') id: string) {
    return this.onlineCourseService.remove(+id);
  }
  // -------------------分类模块------------------  //
  // 分类查询
  @Get('classify')
  @ApiOperation({ summary: '查询所有分类' })
  getclassifyList() {
    return this.onlineCourseService.getclassifyList();
  }
  // 新建分类
  @Post('classify')
  @ApiOperation({ summary: '新增分类' })
  createclassify(@Body() createclassify: CreateCourseclassifyDto) {
    return this.onlineCourseService.createclassify(createclassify);
  }
  // 编辑分类
  @Patch('classify/:id')
  @ApiOperation({ summary: '编辑分类' })
  updateCourseclassify(
    @Param('id') id: number,
    @Body() updateclassify: updateCourseclassifyDto,
  ) {
    return this.onlineCourseService.updateclassify(id, updateclassify);
  }
  // 删除分类
  @Post('classify/delete')
  @ApiOperation({ summary: '删除分类' })
  deleteCourseclassify(@Body() id: DeleteDto) {
    return this.onlineCourseService.deleteclassify(id);
  }
}
