package com.tmerclub.cloud.cuerecycle.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateUtil;
import com.tmerclub.cloud.common.database.dto.PageDTO;
import com.tmerclub.cloud.common.database.util.PageUtil;
import com.tmerclub.cloud.common.database.vo.PageVO;
import com.tmerclub.cloud.cuerecycle.mapper.CueSeriesMapper;
import com.tmerclub.cloud.cuerecycle.model.CueSeries;
import com.tmerclub.cloud.cuerecycle.model.dto.CueSeriesDTO;
import com.tmerclub.cloud.cuerecycle.model.vo.CueSeriesVO;
import com.tmerclub.cloud.cuerecycle.service.CueSeriesService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

/**
 * 球杆系列Service实现类
 *
 * @author : frank
 * @create : 2025-04-11
 */
@Service
public class CueSeriesServiceImpl implements CueSeriesService {

    @Resource
    CueSeriesMapper cueSeriesMapper;

    @Override
    public PageVO<CueSeriesVO> page(PageDTO pageDTO, CueSeriesDTO cueSeriesDTO) {
        return PageUtil.doPage(pageDTO, () -> cueSeriesMapper.list(cueSeriesDTO));
    }

    @Override
    public PageVO<CueSeriesVO> listByBrand(PageDTO pageDTO, CueSeriesDTO cueSeriesDTO) {
        cueSeriesDTO.setSeriesStatus(1);
        return PageUtil.doPage(pageDTO, () -> cueSeriesMapper.list(cueSeriesDTO));
    }

    @Override
    public CueSeriesVO getById(Long seriesId) {
        return cueSeriesMapper.getById(seriesId);
    }

    @Override
    public int save(CueSeriesDTO cueSeriesDTO) {
        CueSeries cueSeries = BeanUtil.toBean(cueSeriesDTO, CueSeries.class);
        cueSeries.setCreateTime(DateUtil.date());
        return cueSeriesMapper.save(cueSeries);
    }

    @Override
    public int update(CueSeriesDTO cueSeriesDTO) {
        CueSeries cueSeries = BeanUtil.toBean(cueSeriesDTO, CueSeries.class);
        cueSeries.setUpdateTime(DateUtil.date());
        return cueSeriesMapper.update(cueSeries);
    }

    @Override
    public int delete(Long seriesId) {
        CueSeriesVO cueSeriesVO = cueSeriesMapper.getById(seriesId);
        CueSeries cueSeries = BeanUtil.toBean(cueSeriesVO, CueSeries.class);
        cueSeries.setUpdateTime(DateUtil.date());
        cueSeries.setDeleted(1);
        return cueSeriesMapper.update(cueSeries);
    }
}