
package com.icomsys.main_vm.biz.common.system.vo;

import com.icomsys.main_vm.biz.common.login.res.UserVo;
import com.icomsys.main_vm.db.jpa.entity.system.TbBotCommonCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

@Getter
@Setter
@NoArgsConstructor
public class SystemCommoncodeInsertReq {
    private String serviceGroup;
    private String major;
    private String minor;
    private String codeName;
    private String attribute1;
    private String attribute2;
    private String attribute3;

    public TbBotCommonCode ofSave(UserVo userVo, String custCode) {
        return TbBotCommonCode.builder()
                .custCode(custCode)
                .minorCode(this.minor)
                .majorCode(this.major)
                .oprMngCode(userVo.getCustCode() + "_RCP_" + this.serviceGroup)
                .codeName(this.codeName)
                .attribute1(this.attribute1)
                .attribute2(this.attribute2)
                .attribute3(this.attribute3)
                .registId(userVo.getUserId())
                .registDate(LocalDateTime.now())
                .updateId(userVo.getUserId())
                .updateDate(LocalDateTime.now())
                .build();
    }

    public TbBotCommonCode ofSave(UserVo userVo, String custCode, String mainServiceGroup) {
        return TbBotCommonCode.builder()
                .custCode(custCode)
                .minorCode(this.minor)
                .majorCode(this.major)
                .oprMngCode(userVo.getCustCode() + "_RCP_" + mainServiceGroup)
                .codeName(this.codeName)
                .attribute1(this.attribute1)
                .attribute2(this.attribute2)
                .attribute3(this.attribute3)
                .registId(userVo.getUserId())
                .registDate(LocalDateTime.now())
                .updateId(userVo.getUserId())
                .updateDate(LocalDateTime.now())
                .build();
    }


    public List<TbBotCommonCode> ofSaveAll(UserVo userVo, List<String> services) {
        List<TbBotCommonCode> result = new ArrayList<>();
        for (String e : services) {
            result.add(TbBotCommonCode.builder()
                    .minorCode(this.minor)
                    .majorCode(this.major)
                    .oprMngCode(userVo.getCustCode() + "_" + "RCP_" + e)
                    .codeName(this.codeName)
                    .attribute1(this.attribute1)
                    .attribute2(this.attribute2)
                    .attribute3(this.attribute3)
                    .registId(userVo.getUserId())
                    .registDate(LocalDateTime.now())
                    .updateId(userVo.getUserId())
                    .updateDate(LocalDateTime.now())
                    .build());
        }
        return result;
    }

    public String getOpr(UserVo userVo) {
        return userVo.getCustCode() + "_" + "RCP_" + this.serviceGroup;
    }

}

