package com.ym.mec.teacher.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.Objects;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ym.mec.auth.api.client.SysUserFeignService;
import com.ym.mec.auth.api.entity.SysUser;
import com.ym.mec.biz.dal.dto.MusicGroupExtracurricularSummaryDto;
import com.ym.mec.biz.dal.page.StudentExerciseMusicGroupQueryInfo;
import com.ym.mec.biz.service.ExtracurricularExercisesMessageService;
import com.ym.mec.biz.service.StudentExtracurricularExercisesSituationService;
import com.ym.mec.common.controller.BaseController;
import com.ym.mec.common.entity.HttpResponseResult;
import com.ym.mec.common.page.PageInfo;
import com.ym.mec.util.date.DateUtil;

@RequestMapping("studentExtracurricularExercisesSituation")
@Api(tags = "课外训练统计服务")
@RestController
public class StudentExtracurricularExercisesSituationController extends BaseController {

    @Autowired
    private StudentExtracurricularExercisesSituationService studentExtracurricularExercisesSituationService;

    @Autowired
    private SysUserFeignService sysUserFeignService;

    @Autowired
    private ExtracurricularExercisesMessageService extracurricularExercisesMessageService;


    @ApiOperation(value = "课外训练乐团列表")
    @GetMapping("/queryStudentExerciseMusicGroupList")
    public HttpResponseResult<PageInfo<MusicGroupExtracurricularSummaryDto>> queryStudentExerciseMusicGroupList(StudentExerciseMusicGroupQueryInfo queryInfo){
        SysUser sysUser = sysUserFeignService.queryUserInfo();
        if(Objects.isNull(sysUser)){
            return failed(HttpStatus.FORBIDDEN,"请登录");
        }
        queryInfo.setTeacherId(sysUser.getId());

        Date date = new Date();
        LocalDate nowDate = LocalDateTime.ofInstant(date.toInstant(), DateUtil.zoneId).toLocalDate();
        if(Objects.isNull(date)){
            nowDate = LocalDateTime.now(DateUtil.zoneId).toLocalDate();
        }

        LocalDate monDayDate = nowDate.with(DateUtil.weekFields.dayOfWeek(), DayOfWeek.MONDAY.getValue());
        LocalDate sunDayDate = nowDate.with(DateUtil.weekFields.dayOfWeek(), DayOfWeek.SUNDAY.getValue());
        
        queryInfo.setMondayDate(monDayDate.toString());
        queryInfo.setSundayDate(sunDayDate.toString());
        
        return succeed(studentExtracurricularExercisesSituationService.queryStudentExerciseMusicGroupList(queryInfo));
    }

}
