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

import com.jeeplus.human.enrollment.enrollmentRegistration.domain.EnrollmentFamilyInfo;
import com.jeeplus.human.enrollment.enrollmentRegistration.domain.EnrollmentSocietyInfo;
import com.jeeplus.human.enrollment.enrollmentRegistration.domain.EnrollmentSocietyInfo;
import com.jeeplus.human.enrollment.enrollmentRegistration.service.EnrollmentSocietyInfoService;
import com.jeeplus.human.enrollment.enrollmentRegistration.service.EnrollmentWorkInfoService;
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;

@Slf4j
@RestController
@Api("社会及行业职务")
@RequestMapping(value = "/societyInfo")
public class EnrollmentSocietyInfoController {

    @Resource
    private EnrollmentSocietyInfoService service;


    /**
     * 保存社会及行业职务
     * @return
     */
    @ApiLog(value = "保存社会及行业职务", type = LogTypeEnum.SAVE)
    @PostMapping("save")
    public ResponseEntity save(@Valid @RequestBody EnrollmentSocietyInfo info) throws Exception {
        service.saveOrUpdateWorkInfo(info);
        return ResponseEntity.ok ("操作成功");
    }

    /**
     * 删除社会及行业职务
     * @return
     */
    @ApiLog(value = "删除社会及行业职务", type = LogTypeEnum.SAVE)
    @PostMapping("delete")
    public ResponseEntity<String> delete(@Valid @RequestBody EnrollmentSocietyInfo info) throws Exception {
        service.removeById(info.getId());
        return ResponseEntity.ok ("操作成功");
    }

    /**
     * 社会及行业职务列表
     * @return
     */
    @ApiLog(value = "社会及行业职务列表", type = LogTypeEnum.SAVE)
    @GetMapping("list")
    public ResponseEntity<List<EnrollmentSocietyInfo>> findList(EnrollmentSocietyInfo info) throws Exception {
        List<EnrollmentSocietyInfo> list = service.findByUserId(info.getUserId(),"5");
        return ResponseEntity.ok (list);
    }

    /**
     * 根据id查询社会及行业职务信息
     * @return
     */
    @ApiLog(value = "根据id查询社会及行业职务信息", type = LogTypeEnum.SAVE)
    @GetMapping("findById")
    public ResponseEntity<EnrollmentSocietyInfo> findById(EnrollmentSocietyInfo info) throws Exception {
        EnrollmentSocietyInfo res = service.findById(info.getId());
        return ResponseEntity.ok (res);
    }


    /**
     * 社会及行业职务用户端列表
     * @return
     */
    @ApiLog(value = "社会及行业职务用户端列表", type = LogTypeEnum.SAVE)
    @GetMapping("findAuditList")
    public ResponseEntity<List<EnrollmentSocietyInfo>> findAuditList(EnrollmentSocietyInfo info) throws Exception {
        List<EnrollmentSocietyInfo> list = service.findByUserId(info.getUserId(),"1");
        return ResponseEntity.ok (list);
    }
}
