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.TbBotUser;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.security.crypto.password.PasswordEncoder;

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

@Getter
@Setter
@NoArgsConstructor
public class SystemBotUserSaveReq {

    private String lastUseServiceGroup;
    private String userId;
    private String pass;
    private String userName;
    private String useYn;
    private String userMail;
    private String userMobile;
    private String roleVal;
    private List<addServiceAuthList> addServiceAuthList;

    @Builder
    public SystemBotUserSaveReq(String lastUseServiceGroup, String userId, String pass, String userName, String useYn, String userMail, String userMobile, String roleVal, List<com.icomsys.main_vm.biz.common.system.vo.addServiceAuthList> addServiceAuthList) {
        this.lastUseServiceGroup = lastUseServiceGroup;
        this.userId = userId;
        this.pass = pass;
        this.userName = userName;
        this.useYn = useYn;
        this.userMail = userMail;
        this.userMobile = userMobile;
        this.roleVal = roleVal;
        this.addServiceAuthList = addServiceAuthList;
    }

//    public TbBotUser toUserCreateSave(UserVo uv, PasswordEncoder pe, String custCode, Long seq, String upper) {
//        return TbBotUser.builder()
//                .userSeq(seq)
//                .custCode(custCode)
//                .lastUseServiceGroup(upper)
//                .roleVal(this.roleVal)
//                .userId(this.userId)
//                .password(pe.encode(this.pass))
//                .userName(this.userName)
//                .eMail(this.userMail)
//                .mobileNo(this.userMobile)
//                .loginCheck(0)
//                .useYn(this.useYn)
//                .registId(uv.getUserId())
//                .registDate(LocalDateTime.now())
//                .updateId(uv.getUserId())
//                .updateDate(LocalDateTime.now())
//                .build();
//
//    }

    public TbBotUser toUserCreateSave(UserVo uv, PasswordEncoder pe, String custCode,  String upper) {
        return TbBotUser.builder()
                .custCode(custCode)
                .lastUseServiceGroup(upper)
                .roleVal(this.roleVal)
                .userId(this.userId)
                .password(pe.encode(this.pass))
                .userName(this.userName)
                .eMail(this.userMail)
                .mobileNo(this.userMobile)
                .loginCheck(0)
                .useYn(this.useYn)
                .registId(uv.getUserId())
                .registDate(LocalDateTime.now())
                .updateId(uv.getUserId())
                .updateDate(LocalDateTime.now())
                .build();

    }
}
