package com.ruoyi.bst.snapshot.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ruoyi.bst.snapshot.domain.Snapshot;
import com.ruoyi.bst.snapshot.domain.SnapshotQuery;
import com.ruoyi.bst.snapshot.domain.SnapshotVO;
import com.ruoyi.bst.snapshot.domain.enums.SnapshotType;
import com.ruoyi.bst.snapshot.domain.vo.SnapshotDateVO;
import com.ruoyi.bst.snapshot.mapper.SnapshotMapper;
import com.ruoyi.bst.snapshot.service.SnapshotService;
import com.ruoyi.common.utils.DateUtils;

/**
 * 快照Service业务层处理
 *
 * @author ruoyi
 * @date 2025-05-08
 */
@Service
public class SnapshotServiceImpl implements SnapshotService
{
    @Autowired
    private SnapshotMapper snapshotMapper;

    /**
     * 查询快照
     *
     * @param id 快照主键
     * @return 快照
     */
    @Override
    public SnapshotVO selectSnapshotById(Long id)
    {
        return snapshotMapper.selectSnapshotById(id);
    }

    /**
     * 查询快照列表
     *
     * @param snapshot 快照
     * @return 快照
     */
    @Override
    public List<SnapshotVO> selectSnapshotList(SnapshotQuery snapshot)
    {
        return snapshotMapper.selectSnapshotList(snapshot);
    }

    /**
     * 新增快照
     *
     * @param snapshot 快照
     * @return 结果
     */
    @Override
    public int insertSnapshot(Snapshot snapshot)
    {
        snapshot.setCreateTime(DateUtils.getNowDate());
        return snapshotMapper.insertSnapshot(snapshot);
    }

    /**
     * 修改快照
     *
     * @param snapshot 快照
     * @return 结果
     */
    @Override
    public int updateSnapshot(Snapshot snapshot)
    {
        return snapshotMapper.updateSnapshot(snapshot);
    }

    /**
     * 批量删除快照
     *
     * @param ids 需要删除的快照主键
     * @return 结果
     */
    @Override
    public int deleteSnapshotByIds(Long[] ids)
    {
        return snapshotMapper.deleteSnapshotByIds(ids);
    }

    /**
     * 删除快照信息
     *
     * @param id 快照主键
     * @return 结果
     */
    @Override
    public int deleteSnapshotById(Long id)
    {
        return snapshotMapper.deleteSnapshotById(id);
    }

    @Override    
    public int record(SnapshotType type, String value) {
        if (type == null) {
            return 0;
        }
        Snapshot po = new Snapshot();
        po.setType(type.getCode());
        po.setValue(value);
        return this.insertSnapshot(po);
    }

    @Override
    public List<SnapshotDateVO> selectSimpleForDate(SnapshotQuery query) {
        return snapshotMapper.selectSimpleForDate(query);
    }
}
