package com.friday.tooldriver.po.taieoc;

import com.friday.operation.api.keepalive.dto.taieoc.OcTenantDictDto;
import com.friday.operation.api.keepalive.dto.taieoc.OcTenantInfoDto;
import com.friday.operation.api.keepalive.dto.taieoc.OcTenantPageDto;
import com.friday.operation.api.keepalive.constant.taieoc.TaieOcConstants;
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 OcTenantPo {
    /**
     * 主键
     */
    private Long id;
    /**
     * 中控信息表主键
     */
    private Long ocInfoId;
    /**
     * 中控租户
     */
    private String ocTenant;
    /**
     * 租户用户名
     */
    private String tenantUser;
    /**
     * 租户密码
     */
    private String tenantPassword;
    /**
     * 火车表最小许可数量
     */
    private int minLicenseNum;

    /**
     * 扩展信息
     */
    private String extInfo;

    private Boolean isValid;
    private Date createTime;
    private Date updateTime;
    private String operator;

    /**
     * 所屬用戶租戶信息
     */
    private String userTenant;

    public static OcTenantInfoDto createInfo(OcTenantPo po){
        return OcTenantInfoDto.builder()
                .ocTenantId(po.getId())
                .ocTenantUser(po.getTenantUser())
                .ocTenantPassword(TaieOcConstants.PASSWORD_MASK)
                .ocTenant(po.getOcTenant())
                .minLicenseNum(po.getMinLicenseNum())
                .build();
    }

    public static OcTenantPageDto createPage(OcTenantPo po){
        OcTenantPageDto pageDto = new OcTenantPageDto();
        pageDto.setOcTenant(po.getOcTenant());
        pageDto.setOcTenantId(po.getId());
        pageDto.setOcTenantUser(po.getTenantUser());
        pageDto.setOcTenantPassword(TaieOcConstants.PASSWORD_MASK);
        pageDto.setMinLicenseNum(po.getMinLicenseNum());
        pageDto.setOperations(Arrays.asList(
                TaieOcConstants.TENANT_SAVE,TaieOcConstants.TENANT_MODIFY,TaieOcConstants.TENANT_RESET,TaieOcConstants.DELETE));
        return pageDto;
    }

    public OcTenantDictDto createDict(){
        return OcTenantDictDto.builder()
                .ocTenant(this.ocTenant)
                .ocTenantId(this.id)
                .build();
    }


    public static OcTenantPo createOcTenantPo(Long ocInfoId, OcTenantInfoDto infoDto){
        return OcTenantPo.builder()
                .id(infoDto.getOcTenantId())
                .ocInfoId(ocInfoId)
                .ocTenant(infoDto.getOcTenant())
                .tenantUser(infoDto.getOcTenantUser())
                .tenantPassword(infoDto.getOcTenantPassword())
                .userTenant(infoDto.getUserTenant())
                .minLicenseNum(infoDto.getMinLicenseNum())
                .userTenant(infoDto.getUserTenant())
                .operator(infoDto.getOperator())
                .build();
    }

}
