package com.propertyManagement.web.controller.business.api;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.dtflys.forest.annotation.NotNull;
import com.propertyManagement.business.domain.bo.WxFamilyMemberBo;
import com.propertyManagement.business.domain.vo.LoginWxUser;
import com.propertyManagement.business.domain.vo.WxFamilyMemberVo;
import com.propertyManagement.business.service.IWxFamilyMemberService;
import com.propertyManagement.business.support.util.AuthUtil;
import com.propertyManagement.common.annotation.Log;
import com.propertyManagement.common.annotation.RepeatSubmit;
import com.propertyManagement.common.core.controller.BaseController;
import com.propertyManagement.common.core.domain.R;
import com.propertyManagement.common.core.validate.AddGroup;
import com.propertyManagement.common.enums.BusinessType;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 家庭成员
 *
 * @author liushuai
 * @date 2025-05-14
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/familyMember")
public class ApiWxFamilyMemberController extends BaseController {

    private final IWxFamilyMemberService iWxFamilyMemberService;

    /**
     * 根据户主查询家庭成员列表
     */
    @GetMapping("/listAllByUserId")
    public R<List<WxFamilyMemberVo>> listAllByUserId() {
        LoginWxUser wxUser = AuthUtil.getWxUser();
        WxFamilyMemberBo familyMemberBo = new WxFamilyMemberBo();
        familyMemberBo.setProprietorId(wxUser.getProprietorId());
        List<WxFamilyMemberVo> memberVoList = iWxFamilyMemberService.queryList(familyMemberBo);
        return R.ok(memberVoList);
    }

    /**
     * 新增家庭成员
     */
    @PostMapping("/add")
    public R<Void> add(@Validated(AddGroup.class) @RequestBody WxFamilyMemberBo bo) {
        return toAjax(iWxFamilyMemberService.insertByBo(bo));
    }

    /**
     * 修改家庭成员
     */
    @PostMapping("/update")
    public R<Void> update(@Validated(AddGroup.class) @RequestBody WxFamilyMemberBo bo) {
        return toAjax(iWxFamilyMemberService.updateByBo(bo));
    }

    /**
     * 删除家庭成员
     */
    @PostMapping("/delete/{id}")
    public R<Void> delete(@Validated(AddGroup.class) @PathVariable("id") Long id) {
        return toAjax(iWxFamilyMemberService.deleteWithValidById(id));
    }

}
