package com.fs.app.controller;

import com.fs.app.annotation.Login;
import com.fs.common.core.domain.R;
import com.fs.his.service.NewcomerWelfareService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
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;

import javax.validation.Valid;

@Api("新手福利弹窗")
@RestController
@RequestMapping("/app/newcomerWelfare")
public class NewcomerWelfareController extends AppBaseController {

    @Autowired
    private NewcomerWelfareService newcomerWelfareService;

    @Login
    @ApiOperation("新手福利状态（含 formSchema；路径B会尝试自动发券）")
    @GetMapping("/state")
    public R state() {
        Long userId = Long.parseLong(getUserId());
        return R.ok().put("data", newcomerWelfareService.getState(userId));
    }

    @Login
    @ApiOperation("提交动态问卷并领取福利（仅路径A，answers 与 form_schema 字段 key 对应）")
    @PostMapping("/submitQuestionnaire")
    public R submitQuestionnaire(@Valid @RequestBody NewcomerWelfareService.SubmitBody body) {
        Long userId = Long.parseLong(getUserId());
        newcomerWelfareService.submitQuestionnaire(userId, body);
        return R.ok("提交成功");
    }
}
