package com.friday.tooldriver.po.taieoc;

import com.alibaba.fastjson.JSON;
import com.friday.operation.api.keepalive.dto.taieoc.GroupPageDto;
import com.friday.operation.api.keepalive.constant.taieoc.TaieOcConstants;
import com.friday.operation.api.tooldriver.dto.rpa.GroupDto;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Arrays;
import java.util.Date;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class OcGroupPo {
    private Long id;
    private Long ocTenantInfoId;
    private String groupName;
    private Long parentId;
    private Boolean isValid;
    private Date createTime;
    private Date updateTime;
    private String operator;
    private String groupKey;
    private String extInfo;

    public static GroupPageDto createPage(OcGroupPo po){
        return GroupPageDto.builder()
                .groupId(po.getId())
                .groupName(po.getGroupName())
                .operations(Arrays.asList(TaieOcConstants.QUERY))
                .build();
    }

    public GroupDto createDto(){
        return GroupDto.builder().name(this.groupName)
                .key(String.valueOf(this.id))
                .parentKey(String.valueOf(this.parentId))
                .extInfo(JSON.parseObject(this.extInfo))
                .build();
    }

}
