package com.thinkunion.park.service.common.entity;

import com.thinkunion.park.service.common.constant.ParkingConstant;
import lombok.Data;
import lombok.experimental.Accessors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author 黄辉
 * @version 1.0
 * @date 2021/6/15 19:24
 * <p>
 * 缓存放行规则返回信息
 */
@Data
@Accessors(chain = true)
public abstract class PassTicket implements Row4LedAbility, VideoAbility {

    public static final Logger logger = LoggerFactory.getLogger(PassTicket.class);
    protected long timestamp;

    /**
     * 车牌号
     */
    protected String plateNo;

    /**
     * 放行状态（ 0 = 不允许放行, 1 = 允许放行 ）
     */
    protected Integer passStatus;

    /**
     * 语音提示
     */
    protected String voice;

    /**
     * 放行原因
     * 1、写入账单表的 outMsg 字段
     * 2、写入账单历史表的 outMsg 字段
     * 3、写入过车记录表的 passMessage 字段
     * 4、作为LED显示内容
     * 5、作为语音播报的内容
     */
    protected String passMessage;

    protected String spcMessage;

    /**
     * 作为月卡账单的LED显示的内容
     */
    protected String monthlyCardLed;

    /**
     * 账单类型：1-临停 2-月卡 3-无牌车，4-特殊车，5-节假日，6-群组,7-异常，8--------放行规则提供，10-团队车，20-错时车
     */
    protected Integer billType;

    protected Integer subParkingType;

    public PassTicket() {
        this.timestamp = System.currentTimeMillis() / 1000L;
    }

    public PassTicket(String plateNo, int passStatus, String passMessage, String monthlyCardLed, int billType) {
        this.plateNo = plateNo;
        this.passStatus = passStatus;
        this.passMessage = passMessage;
        this.monthlyCardLed = monthlyCardLed;
        this.billType = billType;
        this.timestamp = System.currentTimeMillis() / 1000L;
    }

    public PassTicket(String plateNo, int passStatus, String passMessage, String monthlyCardLed, Integer billType,
                      Integer subParkingType) {
        this.plateNo = plateNo;
        this.passStatus = passStatus;
        this.passMessage = passMessage;
        this.monthlyCardLed = monthlyCardLed;
        this.billType = billType;
        this.subParkingType = subParkingType;
        this.timestamp = System.currentTimeMillis() / 1000L;
    }

    public String getPlateNoIfAnonymous() {
        if (this.isAnonymous()) {
            return "无牌车";
        }
        return this.getPlateNo();
    }

    /**
     * 可以通行
     * @return
     */
    public boolean isPassAllow() {
        return passStatus == ParkingConstant.Pass.Allow;
    }

    /**
     * 禁止通行
     * @return
     */
    public boolean isPassForbid() {
        return passStatus == ParkingConstant.Pass.Forbid;
    }

    public boolean isUnknown() {
        return ParkingConstant.BillType.unknown == this.billType;
    }

    public boolean isTemporary() {
        return ParkingConstant.BillType.Temporary == this.billType;
    }

    public boolean isMonthlyCard() {
        return ParkingConstant.BillType.MonthlyCard == this.billType;
    }

    public boolean isAnonymous() {
        return ParkingConstant.BillType.Anonymous == this.billType;
    }

    public boolean isSpecial() {
        return ParkingConstant.BillType.Special == this.billType;
    }

    public boolean isHolidays() {
        return ParkingConstant.BillType.Holidays == this.billType;
    }

    public boolean isGroup() {
        return ParkingConstant.BillType.Group == this.billType;
    }

    public boolean isException() {
        return ParkingConstant.BillType.Exception == this.billType;
    }

    public boolean isTeam() {
        return ParkingConstant.BillType.Team == this.billType;
    }

    public boolean isTimeFree() {
        return ParkingConstant.BillType.TimeFree == this.billType;
    }
}
