package com.purui.prims.headless.server.utils;


import com.purui.prims.auth.api.authentication.pojo.User;
import com.purui.prims.headless.api.pojo.request.DomainReq;
import com.purui.prims.headless.api.pojo.response.DomainResp;
import com.purui.prims.headless.server.persistence.dataobject.DomainDO;
import org.springframework.beans.BeanUtils;

import java.util.HashMap;
import java.util.Map;

public class DomainConvert {

    public static DomainDO convert(DomainReq domainReq, User user) {
        DomainDO domainDO = new DomainDO();
        domainReq.createdBy(user.getUserName());
        BeanUtils.copyProperties(domainReq, domainDO);
        return domainDO;
    }

    public static DomainResp convert(DomainDO domainDO, Map<Long, String> domainFullPathMap) {
        DomainResp domainResp = new DomainResp();
        BeanUtils.copyProperties(domainDO, domainResp);
        domainResp.setFullPath(domainFullPathMap.get(domainDO.getId()));
        return domainResp;
    }

    public static DomainResp convert(DomainDO domainDO) {
        return convert(domainDO, new HashMap<>());
    }

}
