package com.purui.prims.headless.server.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.purui.prims.auth.api.authentication.pojo.User;
import com.purui.prims.common.util.BeanMapper;
import com.purui.prims.headless.api.pojo.request.DecoratorTypeReq;
import com.purui.prims.headless.api.pojo.response.DecoratorTypeResp;
import com.purui.prims.headless.server.persistence.dataobject.DecoratorTypeDO;
import com.purui.prims.headless.server.persistence.mapper.DecoratorTypeDOMapper;
import com.purui.prims.headless.server.service.DecoratorTypeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 修饰词类型
 *
 * @author charlie
 * @date 2024/6/24
 */
@Service
@Slf4j
public class DecoratorTypeServiceImpl extends ServiceImpl<DecoratorTypeDOMapper, DecoratorTypeDO> implements
    DecoratorTypeService {
    @Override
    public boolean saveOrUpdate(DecoratorTypeReq decoratorReq, User user) {
        DecoratorTypeDO decoratorTypeDO = new DecoratorTypeDO();
        BeanMapper.mapper(decoratorReq, decoratorTypeDO);
        return super.saveOrUpdate(decoratorTypeDO);
    }

    @Override
    public void delete(Integer id) {
        baseMapper.deleteById(id);
    }

    @Override
    public List<DecoratorTypeResp> getTypes(DecoratorTypeReq decoratorReq) {
        return super.list().stream().map(decoratorTypeDO -> {
            DecoratorTypeResp decoratorTypeResp = new DecoratorTypeResp();
            BeanMapper.mapper(decoratorTypeDO, decoratorTypeResp);
            return decoratorTypeResp;
        }).collect(Collectors.toList());
    }

    @Override
    public DecoratorTypeResp getType(Integer id) {
        DecoratorTypeDO decoratorTypeDO = super.getById(id);
        DecoratorTypeResp decoratorTypeResp = new DecoratorTypeResp();
        BeanMapper.mapper(decoratorTypeDO, decoratorTypeResp);
        return decoratorTypeResp;
    }
}
