package com.iformall.domain.po;

import lombok.Data;

import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.io.Serializable;
import java.util.Date;
import java.util.List;

@Table(name = "wx_game")
@Data
public class WxGame implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    protected Long id;

    @Transient
    protected List<Long> ids;
    @Transient
    protected String sortColumns;

    /**
     * 租户ID
     */
    @io.swagger.annotations.ApiModelProperty(value = "租户ID", name = "tenantId")
    private String tenantId;
    /**
     * 游戏模板ID
     */
    @io.swagger.annotations.ApiModelProperty(value = "游戏模板ID", name = "gameId")
    private Long gameId;
    /**
     * 游戏状态(0:上架，1：下架)
     */
    @io.swagger.annotations.ApiModelProperty(value = "游戏状态(0:上架，1：下架)", name = "status")
    private Integer status;
    /**
     * 券列表
     */
    @io.swagger.annotations.ApiModelProperty(value = "券列表", name = "couponIds")
    private String couponIds;
    /**
     * 有效日期-开始
     */
    @io.swagger.annotations.ApiModelProperty(value = "有效日期-开始", name = "validStartDate")
    private Date validStartDate;
    /**
     * 有效日期-结束
     */
    @io.swagger.annotations.ApiModelProperty(value = "有效日期-结束", name = "validEndDate")
    private Date validEndDate;
    @io.swagger.annotations.ApiModelProperty(value = "触发条件（-1:不受限制，1:登录触发, 2:主页固定入口,3:购买触发,4:核销触发,5:公众号链接触发,6:二维码触发）", name = "triggleAction")
    private Integer triggleAction;
    /**
     * 玩次数限制
     */
    @io.swagger.annotations.ApiModelProperty(value = "限玩次数（0:不受限制，n：限玩次数）", name = "playLimit")
    private Integer playLimit;

    /**
     * 获奖次数限制
     */
    @io.swagger.annotations.ApiModelProperty(value = "限奖次数（0:不受限制，n：限奖次数）", name = "awardLimit")
    private Integer awardLimit;

    @Transient
    @io.swagger.annotations.ApiModelProperty(value = "已投放券信息")
    protected List<Object> couponIdsList;  // couponChannel


    /**游戏名称*/
    @Transient
    @io.swagger.annotations.ApiModelProperty(value="游戏名称",name="name")
    private String name;
    /**游戏链接*/
    @Transient
    @io.swagger.annotations.ApiModelProperty(value="游戏链接",name="url")
    private String url;
    /**游戏logo，c端游戏入口使用*/
    @Transient
    @io.swagger.annotations.ApiModelProperty(value="游戏logo，c端游戏入口使用",name="imgUrl")
    private String imgUrl;
    /**选项限制（-1：不做限制)*/
    @Transient
    @io.swagger.annotations.ApiModelProperty(value="选项限制（-1：不做限制)",name="optionLimit")
    private Integer optionLimit;
    /**游戏规则说明*/
    @Transient
    @io.swagger.annotations.ApiModelProperty(value="游戏规则说明",name="rules")
    private String rules;
    /**游戏类型(1：卡牌),目前无用*/
    @Transient
    @io.swagger.annotations.ApiModelProperty(value="游戏类型(1：卡牌),目前无用",name="type")
    private Integer type;

    @Transient
    @io.swagger.annotations.ApiModelProperty(value="小程序路径",name="weappPath")
    private String weappPath;

    @Transient
    @io.swagger.annotations.ApiModelProperty(value="小程序二维码Scene",name="weappScene")
    private String weappScene;


    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public List<Long> getIds() {
        return ids;
    }

    public void setIds(List<Long> ids) {
        this.ids = ids;
    }

    public String getSortColumns() {
        return sortColumns;
    }

    public String getTenantId() {
        return tenantId;
    }

    public void setTenantId(String tenantId) {
        this.tenantId = tenantId;
    }

    public Long getGameId() {
        return gameId;
    }

    public void setGameId(Long gameId) {
        this.gameId = gameId;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public String getCouponIds() {
        return couponIds;
    }

    public void setCouponIds(String couponIds) {
        this.couponIds = couponIds;
    }

    public Date getValidStartDate() {
        return validStartDate;
    }

    public void setValidStartDate(Date validStartDate) {
        this.validStartDate = validStartDate;
    }

    public Date getValidEndDate() {
        return validEndDate;
    }

    public void setValidEndDate(Date validEndDate) {
        this.validEndDate = validEndDate;
    }

    public Integer getTriggleAction() {
        return triggleAction;
    }

    public void setTriggleAction(Integer triggleAction) {
        this.triggleAction = triggleAction;
    }

    public Integer getPlayLimit() {
        return playLimit;
    }

    public void setPlayLimit(Integer playLimit) {
        this.playLimit = playLimit;
    }

    public List<Object> getCouponIdsList() {
        return couponIdsList;
    }

    public void setCouponIdsList(List<Object> couponIdsList) {
        this.couponIdsList = couponIdsList;
    }

    public Integer getAwardLimit() {
        return awardLimit;
    }

    public void setAwardLimit(Integer awardLimit) {
        this.awardLimit = awardLimit;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getImgUrl() {
        return imgUrl;
    }

    public void setImgUrl(String imgUrl) {
        this.imgUrl = imgUrl;
    }

    public Integer getOptionLimit() {
        return optionLimit;
    }

    public void setOptionLimit(Integer optionLimit) {
        this.optionLimit = optionLimit;
    }

    public String getRules() {
        return rules;
    }

    public void setRules(String rules) {
        this.rules = rules;
    }

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    public String getWeappPath() {
        if (id == null)
            return "pages/index/index";
        return "pages/index/index?type=gm&id="+id;
    }

    public String getWeappScene() {
        if(id == null)
            return "";
        return "t:gm"+id;
    }

    public void setGameTemplate(WxGameTemplate gameTemplate) {
        if (gameTemplate != null) {
            this.imgUrl = gameTemplate.getImgUrl();
            this.url = gameTemplate.getUrl();
            this.name = gameTemplate.getName();
            this.optionLimit = gameTemplate.getOptionLimit();
            this.rules = gameTemplate.getRules();
            this.type = gameTemplate.getType();
        }
    }

    public static enum Field {
        Id_ASC("`id` ASC"), Id_DESC("`id` DESC")
        , TenantId_ASC("`tenant_id` ASC"), TenantId_DESC("`tenant_id` DESC")
        , GameId_ASC("`game_id` ASC"), GameId_DESC("`game_id` DESC")
        , Status_ASC("`status` ASC"), Status_DESC("`status` DESC")
        , ValidStartDate_ASC("`valid_start_date` ASC"), ValidStartDate_DESC("`valid_start_date` DESC")
        , ValidEndDate_ASC("`valid_end_date` ASC"), ValidEndDate_DESC("`valid_end_date` DESC")
        , TriggleAction_ASC("`triggle_action` ASC"), TriggleAction_DESC("`triggle_action` DESC")
        , PlayLimit_ASC("`play_limit` ASC"), PlayLimit_DESC("`play_limit` DESC")
        , AwardLimit_ASC("`award_limit` ASC"), AwardLimit_DESC("`award_limit` DESC");
        private String value;

        Field(String value) {
            this.value = value;
        }

        public String getValue() {
            return value;
        }

        public void setCol(String value) {
            this.value = value;
        }

        @Override
        public String toString() {
            return this.getValue();
        }
    }

    public void setSortColumns(WxGame.Field... fields) {
        if (fields == null || fields.length == 0) {
            return;
        }
        for (int k = 0; k < fields.length; k++) {
            if (fields[k] == null) {
                return;
            }
        }
        StringBuilder sb = new StringBuilder(fields[0].toString());
        for (int k = 1; k < fields.length; k++) {
            sb.append(",");
            sb.append(fields[k].toString());
        }
        this.sortColumns = sb.toString();
    }

    public void setSortColumns(String sortColumns) {
        if (sortColumns == null || "".equals(sortColumns.trim())) {
            return;
        }
        if (sortColumns.contains(",")) {
            String[] cols = sortColumns.split(",");
            java.util.List<Field> fList = new java.util.ArrayList();
            for (int k = 0; k < cols.length; k++) {
                fList.add(Field.valueOf(cols[k]));
            }
            this.setSortColumns(fList.toArray(new Field[fList.size()]));
        } else {
            this.setSortColumns(Field.valueOf(sortColumns));
        }
    }
}
