package com.yhy.module.core.convert.quota;

import com.yhy.module.core.controller.admin.quota.vo.QuotaAdjustmentRespVO;
import com.yhy.module.core.dal.dataobject.quota.QuotaAdjustmentDO;
import com.yhy.module.core.enums.quota.QuotaAdjustmentTypeEnum;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

import java.util.List;

@Mapper
public interface QuotaAdjustmentConvert {

    QuotaAdjustmentConvert INSTANCE = Mappers.getMapper(QuotaAdjustmentConvert.class);

    default QuotaAdjustmentRespVO convert(QuotaAdjustmentDO bean) {
        if (bean == null) {
            return null;
        }
        QuotaAdjustmentRespVO vo = new QuotaAdjustmentRespVO();
        vo.setId(bean.getId());
        vo.setQuotaItemId(bean.getQuotaItemId());
        vo.setName(bean.getName());
        vo.setContent(bean.getContent());
        vo.setAdjustmentType(bean.getAdjustmentType());
        vo.setAdjustmentRules(bean.getAdjustmentRules());
        vo.setSortOrder(bean.getSortOrder());
        vo.setCreateTime(bean.getCreateTime());
        vo.setUpdateTime(bean.getUpdateTime());

        // 设置调整类型名称
        QuotaAdjustmentTypeEnum typeEnum = QuotaAdjustmentTypeEnum.valueOfCode(bean.getAdjustmentType());
        if (typeEnum != null) {
            vo.setAdjustmentTypeName(typeEnum.getName());
        }

        return vo;
    }

    List<QuotaAdjustmentRespVO> convertList(List<QuotaAdjustmentDO> list);
}
