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

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.stp.StpUtil;
import com.seer.teach.common.ResultBean;
import com.seer.teach.mp.app.controller.req.AppMpSignUpActivityReq;
import com.seer.teach.mp.app.controller.req.TestChildCharacterReq;
import com.seer.teach.mp.app.controller.resp.AppMpSignUpActivityResp;
import com.seer.teach.mp.app.controller.resp.TestChildCharacterResp;
import com.seer.teach.mp.app.service.AppParentAgentActivityService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.AllArgsConstructor;
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.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 家长参与代理商活动控制器 - 应用端
 */
@Tag(name = "App - 家长参与代理商活动管理")
@AllArgsConstructor
@RestController
@RequestMapping("/app/parent/agent/activity")
public class AppParentAgentActivityController {

    private final AppParentAgentActivityService appParentAgentActivityService;

    @PostMapping("/sign-up")
    @SaCheckLogin
    @Operation(summary = "家长报名参加代理商活动")
    public ResultBean<Boolean> signUpForActivity(@RequestBody AppMpSignUpActivityReq request) {
        Integer parentId = StpUtil.getLoginIdAsInt();
        return ResultBean.success(appParentAgentActivityService.signUpForActivityWithInfo(request, parentId));
    }

    @PostMapping("/update-info")
    @SaCheckLogin
    @Operation(summary = "家长更新活动信息")
    public ResultBean<Boolean> updateActivityInfo(@RequestBody AppMpSignUpActivityReq request) {
        Integer parentId = StpUtil.getLoginIdAsInt();
        return ResultBean.success(appParentAgentActivityService.updateActivityInfo(request, parentId));
    }

    @DeleteMapping("/cancel/{id}")
    @SaCheckLogin
    @Operation(summary = "取消报名参加代理商活动")
    public ResultBean<Boolean> cancelSignUp(@PathVariable("id") Integer id) {
        Integer parentId = StpUtil.getLoginIdAsInt();
        return ResultBean.success(appParentAgentActivityService.cancelSignUp(id,parentId));
    }

    @GetMapping("/{agentId}/{activityId}/info")
    @SaCheckLogin
    @Operation(summary = "获取家长参与代理商活动详情")
    public ResultBean<AppMpSignUpActivityResp> getRelationById(@PathVariable("agentId") Integer agentId,@PathVariable("activityId") Integer activityId) {
        Integer parentId = StpUtil.getLoginIdAsInt();
        return ResultBean.success(appParentAgentActivityService.getByActivityIdAndParentId(agentId,activityId,parentId));
    }

    @PostMapping("/test-child-character")
    @SaCheckLogin
    @Operation(summary = "测试孩子性格")
    public ResultBean<TestChildCharacterResp> testChildCharacter(@RequestBody @Valid TestChildCharacterReq request) {
        Integer parentId = StpUtil.getLoginIdAsInt();
        return ResultBean.success(appParentAgentActivityService.testChildCharacter(request, parentId));
    }
}