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.util.PageUtil;
import com.tmerclub.cloud.common.database.dto.PageDTO;
import com.tmerclub.cloud.common.database.vo.PageVO;
import com.tmerclub.cloud.cuerecycle.model.dto.CueBrandDTO;
import com.tmerclub.cloud.cuerecycle.model.vo.CueBrandVO;
import com.tmerclub.cloud.cuerecycle.model.CueBrand;
import com.tmerclub.cloud.cuerecycle.mapper.CueBrandMapper;
import com.tmerclub.cloud.cuerecycle.service.CueBrandService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

/**
 * 球杆品牌Service实现类
 *
 * @author : frank
 * @create : 2025-04-11
 */
@Service
public class CueBrandServiceImpl implements CueBrandService {

    @Resource
    CueBrandMapper cueBrandMapper;

    @Override
    public PageVO<CueBrandVO> page(PageDTO pageDTO, CueBrandDTO cueBrandDTO) {
        return PageUtil.doPage(pageDTO, () -> cueBrandMapper.list(cueBrandDTO));
    }

    @Override
    public PageVO<CueBrandVO> listEnabled(PageDTO pageDTO) {
        CueBrandDTO cueBrandDTO = new CueBrandDTO();
        cueBrandDTO.setBrandStatus(1);
        return PageUtil.doPage(pageDTO, () -> cueBrandMapper.list(cueBrandDTO));
    }

    @Override
    public CueBrandVO getById(Long brandId) {
        return cueBrandMapper.getById(brandId);
    }

    @Override
    public int save(CueBrandDTO cueBrandDTO) {
        CueBrand cueBrand = BeanUtil.toBean(cueBrandDTO, CueBrand.class);
        cueBrand.setCreateTime(DateUtil.date());
        return cueBrandMapper.save(cueBrand);
    }

    @Override
    public int update(CueBrandDTO cueBrandDTO) {
        CueBrand cueBrand = BeanUtil.toBean(cueBrandDTO, CueBrand.class);
        cueBrand.setUpdateTime(DateUtil.date());
        return cueBrandMapper.update(cueBrand);
    }

    @Override
    public int delete(Long brandId) {
        CueBrandVO cueBrandVO = cueBrandMapper.getById(brandId);
        CueBrand cueBrand = BeanUtil.toBean(cueBrandVO, CueBrand.class);
        cueBrand.setUpdateTime(DateUtil.date());
        cueBrand.setDeleted(1);
        return cueBrandMapper.update(cueBrand);
    }
}