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

import com.jeeplus.human.enrollment.enrollmentRegistration.domain.EnrollmentLaborContractInfo;
import com.jeeplus.human.enrollment.enrollmentRegistration.service.EnrollmentLaborContractInfoService;
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;

/**
 * @version 1.0
 */
@Slf4j
@RestController
@Api("劳动合同")
@RequestMapping(value = "/laborContractInfo")
public class EnrollmentLaborContractInfoController {

    @Resource
    private EnrollmentLaborContractInfoService service;


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

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

    /**
     * 劳动合同列表
     * @return
     */
    @ApiLog(value = "教育劳动合同", type = LogTypeEnum.SAVE)
    @GetMapping("list")
    public ResponseEntity<List<EnrollmentLaborContractInfo>> findList(EnrollmentLaborContractInfo info) throws Exception {
        List<EnrollmentLaborContractInfo> list = service.findByUserId(info.getUserId(),"5");
        return ResponseEntity.ok (list);
    }

    /**
     * 根据id查询劳动合同信息
     * @return
     */
    @ApiLog(value = "根据id查询劳动合同信息", type = LogTypeEnum.SAVE)
    @GetMapping("findById")
    public ResponseEntity<EnrollmentLaborContractInfo> findById(EnrollmentLaborContractInfo info) throws Exception {
        EnrollmentLaborContractInfo res = service.findById(info.getId());
        return ResponseEntity.ok (res);
    }
}
