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

import com.ruoyi.bst.ad.domain.Ad;
import com.ruoyi.bst.ad.domain.enums.AdBelong;
import com.ruoyi.bst.ad.service.AdConverter;
import com.ruoyi.common.utils.ServiceUtil;
import org.springframework.stereotype.Service;



@Service
public class AdConverterImpl implements AdConverter {

    @Override
    public Ad toPoByCreate(Ad data) {
            if (data == null) {
            return null;
        }
        Ad po = new Ad();
        po.setBelong(data.getBelong());
        // 基础信息
        if (po.getBelong().equals(AdBelong.STORE.getCode())) {
            ServiceUtil.assertion(data.getAreaId()==null,"商户运营区不可以为空");
            po.setAreaId(data.getAreaId());
        }else{
            po.setAreaId(null);
        }
        po.setType(data.getType());
        po.setPicture(data.getPicture());
        po.setStatus(data.getStatus());
        po.setUrl(data.getUrl());
        po.setUrlType(data.getUrlType());
        po.setAuditStatus(data.getAuditStatus());
        return po;
    }

    @Override
    public Ad toPoByUpdate(Ad data) {
        if (data == null) {
            return null;
        }
        Ad po = new Ad();
        // 基础信息
        po.setBelong(data.getBelong());
        if (po.getBelong().equals(AdBelong.STORE.getCode())) {
            po.setAreaId(data.getAreaId());
        }else{
            po.setAreaId(null);
        }
        po.setType(data.getType());
        po.setPicture(data.getPicture());
        po.setStatus(data.getStatus());
        po.setUrl(data.getUrl());
        po.setUrlType(data.getUrlType());
        po.setAuditStatus(data.getAuditStatus());
        return po;
    }

}
