package org.jeecg.modules.app.controller.my;


import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.modules.app.dto.AddFamilyMembersDTO;
import org.jeecg.modules.app.dto.FindFamilyMembersDTO;
import org.jeecg.modules.system.app.entity.FamilyMembers;
import org.jeecg.modules.system.app.service.IFamilyMembersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 家庭成员
 */
@Slf4j
@Tag(name = "APP家庭成员信息")
@RestController
@RequestMapping("/app/my/familyMembers")
public class AppFamilyMembersController {

    @Autowired
    IFamilyMembersService iFamilyMembersService;


    @GetMapping("/findFamilyMembers")
    @Operation(summary = "分页查询家庭成员")
    public Result<IPage<FamilyMembers>> findFamilyMembers(FindFamilyMembersDTO findFamilyMembersDTO){
        LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        findFamilyMembersDTO.setUserId(loginUser.getId());
        return iFamilyMembersService.findFamilyMembers(findFamilyMembersDTO);
    }


    @PostMapping("/addFamilyMembers")
    @Operation(summary = "添加家庭成员")
    public Result<String> addFamilyMembers(@RequestBody AddFamilyMembersDTO addFamilyMembersDTO){
        LoginUser principal = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        addFamilyMembersDTO.setUserId(principal.getId());
        return iFamilyMembersService.addFamilyMembers(addFamilyMembersDTO);
    }

    @GetMapping("/FindByIdFamilyMembers")
    @Operation(summary = "根据id查询家庭成员")
    public Result<FamilyMembers> addFamilyMembers(@RequestParam("id") String id){
        return Result.ok(iFamilyMembersService.getById(id));
    }

    @PostMapping("/editFamilyMembers")
    @Operation(summary = "修改家庭成员")
    public Result<String> editFamilyMembers(@RequestBody AddFamilyMembersDTO addFamilyMembersDTO){
        return iFamilyMembersService.editFamilyMembers(addFamilyMembersDTO);
    }


    @GetMapping("/deleteFamilyMembers")
    @Operation(summary = "删除家庭成员")
    public Result<String> deleteFamilyMembers(@RequestParam("id") String id){
        return iFamilyMembersService.deleteFamilyMembers(id);
    }

}
