package org.dromara.zhishu.service.impl;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.dromara.zhishu.domain.vo.EmployeeVo;
import org.dromara.zhishu.mapper.EmployeeMapper;
import org.dromara.zhishu.service.EmployeeService;
import org.springframework.stereotype.Service;

import java.time.Instant;
import java.util.List;

@RequiredArgsConstructor
@Service
@Slf4j
public class EmployeeServiceImpl implements EmployeeService {

    private final EmployeeMapper employeeMapper;

    @Override
    public List<EmployeeVo> getEmployeeList(String userId) {
        return employeeMapper.getEmployeeInfo(userId);
    }

    @Override
    public Boolean addEmployee(String employeeId, String employeeName, String userId) {
        EmployeeVo employeeVo = new EmployeeVo();
        employeeVo.setId(employeeId);
        employeeVo.setName(employeeName);
        employeeVo.setUserId(Long.parseLong(userId));
        long timestamp = Instant.now().getEpochSecond();
        employeeVo.setCreatTime(timestamp);
        employeeVo.setUpdateTime(timestamp);
        employeeVo.setDelFlag(0);
        return employeeMapper.addEmployee(employeeVo) > 0;
    }

    @Override
    public Boolean updateEmployee(String employeeId, String employeeName, String userId) {
        long timestampSeconds = Instant.now().getEpochSecond();
        EmployeeVo employeeVo = new EmployeeVo();
        employeeVo.setId(employeeId);
        employeeVo.setName(employeeName);
        employeeVo.setUserId(Long.parseLong(userId));
        employeeVo.setUpdateTime(timestampSeconds);
        return employeeMapper.updateEmployee(employeeVo) > 0;
    }

    @Override
    public Boolean delEmployee(String id, String userId) {
        return employeeMapper.delEmployee(id, Long.parseLong(userId)) > 0;
    }

}
