package com.czg.account.entity;

import com.czg.enums.ShopTableStatusEnum;
import com.mybatisflex.annotation.Column;
import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.KeyType;
import com.mybatisflex.annotation.Table;

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

import java.io.Serial;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 台桌配置 实体类。
 *
 * @author zs
 * @since 2025-02-13
 */
@Data

@NoArgsConstructor
@AllArgsConstructor
@Table("tb_shop_table")
public class ShopTable implements Serializable {

    @Serial
    private static final long serialVersionUID = 1L;

    /**
     * 自增id
     */
    @Id(keyType = KeyType.Auto)
    private Integer id;

    private String name;

    private Long shopId;

    /**
     * 客座数,允许的客座数量
     */
    private Integer maxCapacity;

    /**
     * 台桌排序
     */
    private Integer sort;

    /**
     * 区域Id
     */
    private Integer areaId;

    /**
     * 区域名称
     */
    @Column(ignore = true)
    private String areaName;

    /**
     * 是否接受网络预定
     */
    private Integer isPredate;

    /**
     * 网络预定台桌支付金额
     */
    private BigDecimal predateAmount;

    /**
     * {@link com.czg.enums.ShopTableStatusEnum}
     * 未绑定：unbound
     * 空闲：idle
     * 点餐中：ordering
     * 未结账：unsettled
     * 支付中：paying
     * 已结账 (待清台)：settled
     * 关台：closed
     */
    private String status;
    @Column(ignore = true)
    private String statusMsg;

    @Column(onInsertValue = "now()")
    private LocalDateTime createTime;

    @Column(onInsertValue = "now()", onUpdateValue = "now()")
    private LocalDateTime updateTime;

    /**
     * 二维码
     */
    private String tableCode;

    /**
     * 清台时间(自动清台时使用)
     */
    private LocalDateTime clearTime;
    /**
     * 使用时间
     */
    private LocalDateTime useTime;

    /**
     * 结束时间
     */
    private LocalDateTime endTime;

    /**
     * 已点商品数量
     */
    private Integer productNum;

    /**
     * 总金额
     */
    private BigDecimal totalAmount;

    /**
     * 应付金额
     */
    private BigDecimal realAmount;

    /**
     * 用餐人数
     */
    private Integer useNum;

    private Integer autoClear;
    private Integer autoClearTime;

    public boolean canUseByStatus() {
        return !ShopTableStatusEnum.UNBOUND.equalsVal(status)
                && !ShopTableStatusEnum.SETTLED.equalsVal(status)
                && !ShopTableStatusEnum.SUBSCRIBE.equalsVal(status)
                && !ShopTableStatusEnum.CLOSED.equalsVal(status);
    }

}
