package com.leromro.core.controller;

import java.time.LocalDate;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.leromro.common.core.domain.R;
import com.leromro.core.domain.VolunteerReservationTime;
import com.leromro.core.domain.dto.AddReservationTimesDTO;
import com.leromro.core.domain.vo.VolunteerReservationTimeVO;
import com.leromro.core.facade.VolunteerWorkDateFacade;
import com.leromro.core.service.IVolunteerReservationTimeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.leromro.common.annotation.Log;
import com.leromro.common.core.controller.BaseController;
import com.leromro.common.core.domain.AjaxResult;
import com.leromro.common.enums.BusinessType;
import com.leromro.core.domain.VolunteerWorkDate;
import com.leromro.core.service.IVolunteerWorkDateService;
import com.leromro.common.utils.poi.ExcelUtil;
import com.leromro.common.core.page.TableDataInfo;

/**
 * 志愿者排班日期Controller
 * 
 * @author ruoyi
 * @date 2025-04-07
 */
@RestController
@Api(tags = "志愿者排班日期")
@RequestMapping("/core/volunteer/work-date")
public class VolunteerWorkDateController extends BaseController
{
    @Autowired
    private IVolunteerWorkDateService volunteerWorkDateService;

    @Autowired
    private VolunteerWorkDateFacade workDateFacade;

    /**
     * 修改志愿者排班日期
     */
    @ApiOperation("修改志愿者排班日期及时间")
    @Log(title = "志愿者排班日期", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody List<VolunteerWorkDate> list)
    {
        return volunteerWorkDateService.updateVolunteerWorkDate(list);
    }

    /**
     * 查看志愿者排班日期及时间"
     */
    @ApiOperation("查看志愿者排班日期及时间")
    @GetMapping("/getWorkDateAndTime")
    public R<List<VolunteerWorkDate>> getWorkDateAndTime()
    {
        return volunteerWorkDateService.getWorkDateAndTime();
    }



    /**
     * 根据志愿者id获取志愿者所有排班日期
     */
    @ApiOperation(value = "获取志愿者所有排班日期", notes = "传入志愿者id，返回数组")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "volunteerId", value = "志愿者id", required = true)
    })
    @GetMapping("/getVolunteerWorkDate")
    public R<List<LocalDate>> getVolunteerWorkDate(@RequestParam("volunteerId") Long volunteerId) {
        List<LocalDate> list = volunteerWorkDateService.list(new LambdaQueryWrapper<VolunteerWorkDate>()
                .eq(VolunteerWorkDate::getVolunteerId, volunteerId))
                .stream().map(VolunteerWorkDate::getWorkDate).sorted().collect(Collectors.toList());
        return R.ok(list);
    }


    /**
     * 根据日期获取志愿者工作时间
     */
    @ApiOperation(value = "获取志愿者所有排班时间", notes = "传入志愿者id和指定日期，返回数组")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "volunteerId", value = "志愿者id", required = true),
            @ApiImplicitParam(name = "date", value = "指定日期，格式2025-04-12", required = true)
    })
    @GetMapping("/getTimesByDate")
    public R<List<VolunteerReservationTimeVO>> getTimesByDate(@RequestParam("volunteerId") Long volunteerId,
                                                              @RequestParam("date")  @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate date) {
        return workDateFacade.getTimesByDate(volunteerId,date);
    }

    /**
     * 新增预约志愿者时间
     */
//    @ApiOperation("新增预约志愿者时间")
//    @PostMapping("/addReservationTimes")
//    public R<Boolean> addReservationTimes(@RequestBody AddReservationTimesDTO dto) {
//        return workDateFacade.addReservationTimes(dto);
//    }

}
