package com.jeeplus.human.enrollment.enrollmentRegistration.controller;

import com.jeeplus.human.enrollment.enrollmentRegistration.domain.EnrollmentFamilyInfo;
import com.jeeplus.human.enrollment.enrollmentRegistration.domain.EnrollmentPerformanceInfo;
import com.jeeplus.human.enrollment.enrollmentRegistration.service.EnrollmentFamilyInfoService;
import com.jeeplus.logging.annotation.ApiLog;
import com.jeeplus.logging.constant.enums.LogTypeEnum;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @author 王强
 * @version 1.0
 */
@Slf4j
@RestController
@Api("家庭成员")
@RequestMapping(value = "/familyInfo")
public class EnrollmentFamilyInfoController {

    @Resource
    private EnrollmentFamilyInfoService service;


    /**
     * 保存家庭成员
     * @return
     */
    @ApiLog(value = "保存家庭成员", type = LogTypeEnum.SAVE)
    @PostMapping("save")
    public ResponseEntity save(@Valid @RequestBody EnrollmentFamilyInfo info) throws Exception {
        service.saveOrUpdateInfo(info);
        return ResponseEntity.ok ("操作成功");
    }

    /**
     * 删除家庭成员
     * @return
     */
    @ApiLog(value = "删除家庭成员", type = LogTypeEnum.SAVE)
    @PostMapping("delete")
    public ResponseEntity<String> delete(@Valid @RequestBody EnrollmentFamilyInfo info) throws Exception {
        service.removeById(info.getId());
        return ResponseEntity.ok ("操作成功");
    }

    /**
     * 语言能力
     * @return
     */
    @ApiLog(value = "家庭成员", type = LogTypeEnum.SAVE)
    @GetMapping("list")
    public ResponseEntity<List<EnrollmentFamilyInfo>> findList(EnrollmentFamilyInfo info) throws Exception {
        List<EnrollmentFamilyInfo> list = service.findByUserId(info.getUserId(),"5");
        return ResponseEntity.ok (list);
    }

    /**
     * 根据id查询家庭成员信息
     * @return
     */
    @ApiLog(value = "根据id查询家庭成员信息", type = LogTypeEnum.SAVE)
    @GetMapping("findById")
    public ResponseEntity<EnrollmentFamilyInfo> findById(EnrollmentFamilyInfo info) throws Exception {
        EnrollmentFamilyInfo res = service.findById(info.getId());
        return ResponseEntity.ok (res);
    }



    /**
     * 家庭成员用户端列表
     * @return
     */
    @ApiLog(value = "家庭成员用户端列表", type = LogTypeEnum.SAVE)
    @GetMapping("findAuditList")
    public ResponseEntity<List<EnrollmentFamilyInfo>> findAuditList(EnrollmentFamilyInfo info) throws Exception {
        List<EnrollmentFamilyInfo> list = service.findByUserId(info.getUserId(),"1");
        return ResponseEntity.ok (list);
    }
}
