package org.jeecg.modules.userCode.controller;

import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.modules.bean.LoginReq;
import org.jeecg.modules.postBean.ReqUserRole;
import org.jeecg.modules.postBean.ReqUserRole2;
import org.jeecg.modules.tbTask.entity.TbTask;
import org.jeecg.modules.tbTask.service.ITbTaskService;
import org.jeecg.modules.userCode.model.req.TaskReq;
import org.jeecg.modules.userCode.model.req.TaskReq2;
import org.jeecg.modules.userCode.service.AppletLoginService;
import org.jeecg.modules.userCode.service.UserService;
import org.jeecg.modules.utils.ValidateTool;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * 服务化 system模块 对外接口请求类
 *
 * @author: jeecg-boot
 */
@Slf4j
@RestController
@RequestMapping("/user")
@Api(tags = "登陆选择身份等接口")
public class UserController {

    @Resource
    private AppletLoginService appletLoginService;
    @Resource
    private UserService userService;
    @Resource
    private ITbTaskService tbTaskService;

    //小程序授权登录
    @ApiOperation(value = "小程序-登录接口", notes = "小程序-登录接口")
    @GetMapping("/login")
    public Result<?> login(LoginReq loginReq) {
        return appletLoginService.appletLogin(loginReq);
    }


    @ApiOperation(value = "求职者填写信息")
    @RequestMapping(value = "/role", method = RequestMethod.POST)
    public Result<JSONObject> role(@RequestBody ReqUserRole2 reqUserRole, @RequestHeader("X-Access-Token") String token) {
        if (ValidateTool.isNull(reqUserRole)) {
            return Result.error("参数错误");
        }
        return appletLoginService.role2(reqUserRole, token);
    }


    @ApiOperation(value = "招聘方填写信息")
    @RequestMapping(value = "/roleBoss", method = RequestMethod.POST)
    public Result<JSONObject> roleBoss(@RequestBody ReqUserRole reqUserRole, @RequestHeader("X-Access-Token") String token) {
        if (ValidateTool.isNull(reqUserRole)) {
            return Result.error("参数错误");
        }

        return appletLoginService.role(reqUserRole, token);
    }


    @ApiOperation(value = "公司发布任务", notes = "发布任务")
    @PostMapping(value = "/addTask")
    public Result<String> addTask(@RequestBody TaskReq tbTask, @RequestHeader("X-Access-Token") String token) {
        if (ValidateTool.isNull(tbTask)) {
            throw new JeecgBootException("请填写资料");
        }
        userService.addTask(tbTask, token);
        return Result.OK("添加成功！");
    }


    @ApiOperation(value = "师傅发布", notes = "师傅发布")
    @PostMapping(value = "/addTask2")
    public Result<String> addTask2(@RequestBody TaskReq2 tbTask, @RequestHeader("X-Access-Token") String token) {
        if (ValidateTool.isNull(tbTask)) {
            throw new JeecgBootException("请填写资料");
        }
        userService.addTask2(tbTask, token);
        return Result.OK("添加成功！");
    }


    /**
     * 查看师傅/工作详情
     *
     * @param id
     * @return
     */
    //@AutoLog(value = "tb_user_role-通过id查询")
    @ApiOperation(value = "大厅信息查询详情", notes = "大厅信息查询详情")
    @GetMapping(value = "/getTaskById")
    public Result<TbTask> getTaskById(@RequestParam(name = "id", required = true) String id) {
        TbTask tbTask = tbTaskService.getById(id);
        if (tbTask == null) {
            return Result.error("未找到对应数据");
        }
        return Result.OK(tbTask);
    }




}
