package com.leromro.core.controller;


import com.leromro.common.core.domain.AjaxResult;
import com.leromro.common.core.domain.R;
import com.leromro.common.core.page.TableDataInfo;
import com.leromro.common.utils.SecurityUtils;
import com.leromro.core.domain.VolunteerInfo;
import com.leromro.core.domain.vo.VolunteerInfoVO;
import com.leromro.core.service.IVolunteerInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.leromro.common.utils.PageUtils.startPage;

/**
 * 志愿者信息
 * @author lr
 * @since 2025-04-07
 */
@Api(tags = "志愿者注册以及查询")
@RestController
@RequestMapping("/core/volunteer/info")
public class VolunteerInfoController {
    @Autowired
    private IVolunteerInfoService volunteerInfoService;
    /**
     * 新增志愿者信息
     * 已测试
     */
    @ApiOperation( value = "新增志愿者信息",notes = "传入路径参数 大分类，传入对象参数志愿者信息")
    @PostMapping("/newVolunteerInfo/{serviceCategory}")
    public AjaxResult newVolunteerInfoByuserId(@RequestBody VolunteerInfo volunteerInfo, @PathVariable Long serviceCategory){
        Long userId = SecurityUtils.getUserId();
        volunteerInfoService.newVolunteerInfoByuserId(volunteerInfo,userId,serviceCategory);
        return AjaxResult.success();
    }
    /**
     * 修改志愿者信息
     * 未测试
     */
    @ApiOperation(value = "修改志愿者信息" , notes = "传入志愿者修改后的对象")
    @PutMapping("/updateInfo")
    public AjaxResult updateVolunteerInfo(@RequestBody VolunteerInfoVO volunteerInfoVO){
        boolean b = volunteerInfoService.updateById(volunteerInfoVO);
        return AjaxResult.success();
    }
    /**
     * 修改志愿者信息
     * 已测试
     */
    @ApiOperation(value = "志愿者信息回显" , notes = "传入大分类，返回大分类中志愿者已有信息")
    @GetMapping("/volunteerInfo")
    public R<VolunteerInfo> selectVolunteerInfo(Long serviceCategory){
        Long userId = SecurityUtils.getUserId();
        VolunteerInfo info = volunteerInfoService.selectByUserID(serviceCategory,userId);
        return R.ok(info);
    }
    /**
     * 修改志愿者信息
     * 已测试
     */
    @ApiOperation(value = "查询志愿者信息列表",notes = "传入进行分类的字段，根据分类字段查询，返回List 集合")
    @GetMapping("/list")
    public R<List<VolunteerInfo>> list(VolunteerInfo volunteerInfo)
    {
        startPage();
        List<VolunteerInfo> list = volunteerInfoService.selectVolunteerInfoList(volunteerInfo);
        return R.ok(list);
    }
    /**
     * 获取志愿者信息详细信息
     * 已测试
     */
    @ApiOperation( value = "获取志愿者信息详细信息",notes = "传入志愿者id， 返回志愿者的信息")
    @GetMapping(value = "/getDetails/{volunteerId}")
    public R<VolunteerInfo> getInfo(@PathVariable("volunteerId") Long volunteerId)
    {
        return R.ok(volunteerInfoService.selectLVolunteerInfoByVolunteerId(volunteerId));
    }

  /*  @ApiOperation("用户已注册志愿者查询")
    @GetMapping("/havenRegister")
    public Void selectUserHavenRegister(){
        Long userId = SecurityUtils.getUserId();
        volunteerInfoService.selectHavenRegisterByUserID(userId);
    }*/
}
