package com.iformall.domain.po.msg;

import com.iformall.domain.dto.WxCUserBasicInfoFilterListDto;
import com.iformall.domain.po.WxCouponInject;
import com.iformall.domain.po.WxMsgConfig;
import com.iformall.domain.po.WxTags;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;

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

@Table(name = "wx_msg")
@Data
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
public class WxMsg extends BaseMsg {
    private static final long serialVersionUID = 1L;

    @Id
    protected Long id;

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

    @io.swagger.annotations.ApiModelProperty(value = "租户ID", name = "tenantId")
    private String tenantId;
    @io.swagger.annotations.ApiModelProperty(value = "模板id", name = "modelId")
    private Long modelId;
    @io.swagger.annotations.ApiModelProperty(value = "内容", name = "msg")
    private String msg;
    @io.swagger.annotations.ApiModelProperty(value = "发送时间", name = "sendtime")
    private String sendtime;
    @io.swagger.annotations.ApiModelProperty(value = "发送时间", name = "createtime")
    private Date createtime;
    @io.swagger.annotations.ApiModelProperty(value = "预计发送数量", name = "expectSendNumber")
    private Integer expectSendNumber;
    @io.swagger.annotations.ApiModelProperty(value = "成功数量", name = "successNumber")
    private Integer successNumber;
    @io.swagger.annotations.ApiModelProperty(value = "错误数量", name = "errorNumber")
    private Integer errorNumber;
    @io.swagger.annotations.ApiModelProperty(value = "", name = "returnResult")
    private String returnResult;
    @io.swagger.annotations.ApiModelProperty(value = "", name = "phones")
    private String phones;
    @io.swagger.annotations.ApiModelProperty(value = "", name = "signature")
    private String signature;
    @io.swagger.annotations.ApiModelProperty(value = "", name = "isright")
    private Integer isright;
    @io.swagger.annotations.ApiModelProperty(value = "", name = "name")
    private String name;
    @io.swagger.annotations.ApiModelProperty(value = "发送状态0失败1成功", name = "sendstatus")
    private Integer sendstatus;

    @io.swagger.annotations.ApiModelProperty(value = "excelpath", name = "excelpath")
    private String excelpath;

    /*发送人群标签**/
    @io.swagger.annotations.ApiModelProperty(value="发送人群标签",name="tags")
    private String tags;

    @io.swagger.annotations.ApiModelProperty(value = "标签人群", name = "label")
    private String label;

    @io.swagger.annotations.ApiModelProperty(value = "状态0未发送 1已发送 2草稿箱", name = "status")
    private Integer status;

    @io.swagger.annotations.ApiModelProperty(value = "1标签短信2精准投放", name = "way")
    private Integer way;

    @io.swagger.annotations.ApiModelProperty(value = "couponInjectId", name = "couponInjectId")
    private Long couponInjectId;


    //用于mq发送消息
    private WxMsgConfig wxMsgConfig;
    private WxCouponInject couponInject;

    public String getTags() {
        return tags;
    }

    public void setTags(String tags) {
        this.tags = tags;
    }


    @Transient
    List<WxCUserBasicInfoFilterListDto> filterList;

    public List<WxCUserBasicInfoFilterListDto> getFilterList() {
        return filterList;
    }

    public void setFilterList(List<WxCUserBasicInfoFilterListDto> filterList) {
        this.filterList = filterList;
    }


    public WxMsgConfig getWxMsgConfig() {
        return wxMsgConfig;
    }

    public void setWxMsgConfig(WxMsgConfig wxMsgConfig) {
        this.wxMsgConfig = wxMsgConfig;
    }

    public WxCouponInject getCouponInject() {
        return couponInject;
    }

    public void setCouponInject(WxCouponInject couponInject) {
        this.couponInject = couponInject;
    }

    public static enum Field {
        Id_ASC("`id` ASC"), Id_DESC("`id` DESC")
        , TenantId_ASC("`tenant_id` ASC"), TenantId_DESC("`tenant_id` DESC")
        , ModelId_ASC("`model_id` ASC"), ModelId_DESC("`model_id` DESC")
        , Msg_ASC("`msg` ASC"), Msg_DESC("`msg` DESC")
        , Sendtime_ASC("`sendtime` ASC"), Sendtime_DESC("`sendtime` DESC")
        , Createtime_ASC("`createtime` ASC"), Createtime_DESC("`createtime` DESC")
        , ExpectSendNumber_ASC("`expect_send_number` ASC"), ExpectSendNumber_DESC("`expect_send_number` DESC")
        , SuccessNumber_ASC("`success_number` ASC"), SuccessNumber_DESC("`success_number` DESC")
        , ErrorNumber_ASC("`error_number` ASC"), ErrorNumber_DESC("`error_number` DESC")
        , ReturnResult_ASC("`return_result` ASC"), ReturnResult_DESC("`return_result` DESC")
        , Phones_ASC("`phones` ASC"), Phones_DESC("`phones` DESC")
        , Signature_ASC("`signature` ASC"), Signature_DESC("`signature` DESC")
        , Isright_ASC("`isright` ASC"), Isright_DESC("`isright` DESC")
        , Name_ASC("`name` ASC"), Name_DESC("`name` DESC")
        , Sendstatus_ASC("`sendstatus` ASC"), Sendstatus_DESC("`sendstatus` 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(WxMsg.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));
        }
    }
}
