package com.seer.teach.user.app.user.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.stp.StpUtil;
import com.seer.teach.common.ResultBean;
import com.seer.teach.common.annotation.DecryptionAnnotation;
import com.seer.teach.common.annotation.EncryptionAnnotation;
import com.seer.teach.common.annotation.LogPrint;
import com.seer.teach.user.app.user.controller.resp.AppMyFamilyResp;
import com.seer.teach.user.app.user.controller.resp.AppUserInfoResp;
import com.seer.teach.user.app.user.service.AppMyFamilyService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@EncryptionAnnotation
@DecryptionAnnotation
@RestController
@Tag(name = "App - 我的家庭接口")
@Validated
@LogPrint
@SaCheckLogin(type = StpUtil.TYPE)
@RequiredArgsConstructor
@RequestMapping("/app/my-family")
public class AppMyFamilyController {

    private final AppMyFamilyService appMyFamilyService;

    @Operation(summary = "获取孩子列表")
    @GetMapping("/{familyId}/children/list")
    @SaCheckPermission("app:user:family:children")
    public ResultBean<List<AppUserInfoResp>> getChildrenList(@PathVariable("familyId") Integer familyId) {
        return ResultBean.success(appMyFamilyService.getChildrenList(StpUtil.getLoginIdAsInt(),familyId));
    }

    @Operation(summary = "获取监护人列表")
    @GetMapping("/{familyId}/guardian/list")
    @SaCheckPermission("app:user:family:guardian")
    public ResultBean<List<AppUserInfoResp>> getGuardianList(@PathVariable("familyId") Integer familyId) {
        return ResultBean.success(appMyFamilyService.getGuardianList(StpUtil.getLoginIdAsInt(),familyId));
    }

    @GetMapping("/{familyId}/detail")
    @Operation(summary = "家庭的详情")
    @SaCheckPermission("app:user:family:detail")
    public ResultBean<AppMyFamilyResp> getMyFamilyDetail(@PathVariable("familyId") Integer familyId) {
        AppMyFamilyResp result = appMyFamilyService.getMyFamilyDetail(StpUtil.getLoginIdAsInt(),familyId);
        return ResultBean.success(result);
    }

    @Operation(summary = "移除监护人")
    @DeleteMapping("/{familyId}/guardian/{guardianId}")
    @SaCheckPermission("app:user:family:guardian:remove")
    public ResultBean<Boolean> removeGuardian(@PathVariable("familyId") @Parameter(description = "家庭id") Integer familyId,
                                           @PathVariable("guardianId") @Parameter(description = "被移除的监护人ID") Integer guardianId) {
        return ResultBean.success(appMyFamilyService.removeGuardian(StpUtil.getLoginIdAsInt(), familyId, guardianId));
    }
}