package com.friday.tooldriver.po.taieoc;

import com.friday.operation.api.keepalive.dto.taieoc.BadgeInfoDto;
import com.friday.operation.api.keepalive.dto.taieoc.BadgeReqDto;
import com.friday.operation.api.keepalive.constant.taieoc.TaieOcConstants;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.text.DecimalFormat;
import java.util.Date;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class BadgePo {
    private Long id;
    /**
     * 工牌密钥
     */
    private String secretKey;
    /**
     * 工牌类型
     */
    private String badgeType;
    /**
     * 工牌总数
     */
    private Integer badgeCount;
    /**
     * 工牌版本
     */
    private String version;
    /**
     * 中控租户主键
     */
    private Long ocTenantId;
    /**
     * 工牌说明
     */
    private String badgeDesc;

    private int isValid;
    private Date createTime;
    private Date updateTime;
    private String operator;
    /**
     * 已用工牌数量
     */
    private Integer badgeUseCount;

    private String userTenant;

    public static BadgePo createPO(BadgeReqDto reqDto){
        return BadgePo.builder()
                .id(reqDto.getBadgeId())
                .ocTenantId(reqDto.getOcTenantId())
                .secretKey(reqDto.getBadgeSecretKey())
                .badgeType(reqDto.getBadgeType())
                .badgeCount(reqDto.getBadgeNum())
                .badgeDesc(reqDto.getBadgeDesc())
                .operator(reqDto.getOperator())
                .version(reqDto.getBadgeVersion())
                .userTenant(reqDto.getUserTenant())
                .build();
    }

    public BadgeInfoDto createInfo(){
        DecimalFormat df = new DecimalFormat(TaieOcConstants.PERCENT_FORMAT);
        return BadgeInfoDto.builder()
                .badgeId(id)
                .ocTenantId(ocTenantId)
                .badgeSecretKey(secretKey)
                .badgeType(badgeType)
                .badgeNum(badgeCount)
                .badgeUsedNum(badgeUseCount + TaieOcConstants.LEFT_BRACKET + df.format(badgeUseCount/badgeCount) + TaieOcConstants.RIGHT_BRACKET)
                .badgeDesc(badgeDesc)
                .operator(operator)
                .badgeVersion(version)
                .operations(TaieOcConstants.BADGE_PAGE_OPERATION)
                .build();
    }
}
