package com.friday.tooldriver.dto.smartrpa;

import com.friday.operation.api.keepalive.constant.smartrpa.LicenseState;
import com.friday.operation.api.keepalive.constant.smartrpa.RobotState;
import com.friday.operation.api.tooldriver.dto.rpa.RobotDto;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.time.LocalDateTime;

import static com.friday.operation.api.keepalive.constant.smartrpa.LicenseState.*;
import static com.friday.operation.api.keepalive.constant.smartrpa.RobotState.*;

/**
 * @Author YaoYao
 * @Date Created In 16:50 2022/12/12
 * @Description 神码robot
 * @Modified By
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class SmartRobotDto implements Serializable {
    /**
     * 主键ID
     */
    private Integer id;
    /**
     * 机器码
     */
    private String machineCode;
    /**
     * 机器用户
     */
    private String machineLoginUser;
    /**
     * 机器名称
     */
    private String robotKey;
    /**
     * 机器状态
     * {@link RobotState}
     */
    private String robotState;
    /**
     * 机器状态上次更新时间
     */
    private LocalDateTime robotStateLastUpdateTime;
    /**
     * 机器状态
     * {@link RobotState}
     */
    private String robotStateToChange;
    /**
     * 许可状态
     * {@link LicenseState}
     */
    private String licenseState;
    /**
     * 许可状态上次更新时间
     */
    private LocalDateTime licenseLastUpdateTime;

    /**
     * 机器是否需要登录认证
     */
    private String authState;


    /**
     * 中控租戶id
     */
    private Long ocTenantId;


    public RobotDto transferToRobotDto(){
        return RobotDto.builder()
                .key(robotKey)
                .state(robotState)
                .licensed(LicenseState.Enabled.getState().equals(licenseState))
                .build();
    }

    public boolean licenseOrRobotStateToChange(){
        return ToggleOn.getState().equals(robotState) || ToggleOff.getState().equals(robotState)
                || Available.getState().equals(robotStateToChange) || Maintenance.getState().equals(robotStateToChange);
    }
}
