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

import com.ruoyi.bst.ad.domain.Ad;
import com.ruoyi.bst.ad.service.AdConverter;
import com.ruoyi.bst.agreement.domain.Agreement;
import com.ruoyi.bst.agreement.domain.enums.AgreementContentType;
import com.ruoyi.bst.agreement.service.AgreementConverter;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.ServiceUtil;
import org.springframework.stereotype.Service;

import java.util.Objects;


@Service
public class AgreementConverterImpl implements AgreementConverter {

    @Override
    public Agreement toPoByCreate(Agreement data) {
        if (data == null) {
            return null;
        }
        Agreement po = new Agreement();
        // 基础信息
        if (Objects.equals(data.getContentType(), AgreementContentType.TEXT.getCode())){
            po.setAreaId(data.getAreaId());
        }
        po.setTitle(data.getTitle());
        if (SecurityUtils.isAdmin()){
            po.setContentType(data.getContentType());
        }else po.setContentType(
            AgreementContentType.TEXT.getCode()
        );
        po.setAgreementType(data.getAgreementType());
        po.setBrief(data.getBrief());
        po.setContent(data.getContent());
        return po;
    }

    @Override
    public Agreement toPoByUpdate(Agreement data) {
        if (data == null) {
            return null;
        }
        Agreement po = new Agreement();
        // 基础信息
        if (Objects.equals(data.getContentType(), AgreementContentType.TEXT.getCode())){
            po.setAreaId(data.getAreaId());
        }
        po.setId(data.getId());
        po.setTitle(data.getTitle());
        if (SecurityUtils.isAdmin()){
            po.setContentType(data.getContentType());
        }else po.setContentType(AgreementContentType.TEXT.getCode());
        po.setAgreementType(data.getAgreementType());
        po.setBrief(data.getBrief());
        po.setContent(data.getContent());
        return po;

    }

}
