package com.ruoyi.ss.store.domain;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonView;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity;
import com.ruoyi.common.core.domain.JsonViewProfile;
import com.ruoyi.common.core.domain.ValidGroup;
import com.ruoyi.common.utils.RegexpUtils;
import com.ruoyi.common.valid.EnumValid;
import com.ruoyi.ss.store.domain.enums.StoreType;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.validator.constraints.Range;
import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
import java.math.BigDecimal;
import java.time.LocalTime;

/**
 * 店铺对象 sm_device_group
 *
 * @author 邱贞招
 * @date 2024-02-21
 */
@Data
public class Store extends BaseEntity
{
    private static final long serialVersionUID = 1L;

    /** id */
    @ApiModelProperty("店铺id")
    @NotNull(message = "店铺id不能为空", groups = {ValidGroup.Update.class, ValidGroup.FrontUpdate.class})
    @JsonView({JsonViewProfile.App.class, StoreView.ListCount.class})
    private Long storeId;

    /** 店铺名称 */
    @Excel(name = "店铺名称")
    @ApiModelProperty("店铺名称")
    @NotNull(message = "店铺名称不能为空", groups = {ValidGroup.Create.class, ValidGroup.FrontCreate.class})
    @Size(min = 1, max = 20, message = "店铺名称长度必须在1~60之间")
    @JsonView({JsonViewProfile.App.class, StoreView.ListCount.class})
    private String name;

    /** 用户 */
    @Excel(name = "用户")
    @ApiModelProperty("用户id")
    @NotNull(message = "用户id不能为空", groups = {ValidGroup.Create.class})
    private Long userId;

    /** 店铺图片 */
    @Excel(name = "店铺图片")
    @JsonView(JsonViewProfile.App.class)
    private String picture;

    /** 门店地址 */
    @Excel(name = "门店地址")
    @NotNull(message = "门店地址不能为空", groups = {ValidGroup.Create.class, ValidGroup.FrontCreate.class})
    @Size(min = 1, max = 200, message = "门店地址长度必须在1~200之间")
    @JsonView(JsonViewProfile.App.class)
    private String address;

    /** 定位经度 */
    @Excel(name = "定位经度")
    @NotNull(message = "定位经度不能为空", groups = {ValidGroup.Create.class, ValidGroup.FrontCreate.class})
    @Range(min = -180, max = 180, message = "定位经度必须在-180~180之间")
    @JsonView(JsonViewProfile.App.class)
    private BigDecimal lng;

    /** 定位纬度 */
    @Excel(name = "定位纬度")
    @NotNull(message = "定位纬度不能为空", groups = {ValidGroup.Create.class, ValidGroup.FrontCreate.class})
    @Range(min = -90, max = 90, message = "定位纬度必须在-90~90之间")
    @JsonView(JsonViewProfile.App.class)
    private BigDecimal lat;

    /** 设备排序 */
    @ApiModelProperty("店铺排序，越小越靠前")
    @JsonView(StoreView.ListCount.class)
    private Integer groupSort;

    @ApiModelProperty("是否默认")
    @JsonView(StoreView.ListCount.class)
    private Boolean isDefault;

    /** 营业时间起始 */
    @Excel(name = "营业时间起始", width = 30, dateFormat = "HH:mm")
    @DateTimeFormat(pattern = "HH:mm")
    @JsonFormat(pattern = "HH:mm", timezone = "GMT+8")
    @NotNull(message = "营业时间起始不能为空", groups = {ValidGroup.Create.class, ValidGroup.FrontCreate.class})
    @JsonView(JsonViewProfile.App.class)
    private LocalTime businessTimeStart;

    /** 营业时间结束 */
    @Excel(name = "营业时间结束", width = 30, dateFormat = "HH:mm")
    @DateTimeFormat(pattern = "HH:mm")
    @JsonFormat(pattern = "HH:mm", timezone = "GMT+8")
    @NotNull(message = "营业时间结束不能为空", groups = {ValidGroup.Create.class, ValidGroup.FrontCreate.class})
    @JsonView(JsonViewProfile.App.class)
    private LocalTime businessTimeEnd;

    /** 省 */
    @Excel(name = "省")
    @Size(max = 30, message = "省长度不允许超过30字符")
    @JsonView(JsonViewProfile.App.class)
    private String province;

    /** 市 */
    @Excel(name = "市")
    @Size(max = 60, message = "市长度不允许超过60字符")
    @JsonView(JsonViewProfile.App.class)
    private String city;

    /** 区县 */
    @Excel(name = "区县")
    @Size( max = 60, message = "区县长度不允许超过60字符")
    @JsonView(JsonViewProfile.App.class)
    private String county;

    @Excel(name = "店铺类型")
    @ApiModelProperty("店铺类型（1：商场，2：学校，3：娱乐场所，4：出租房，5：其它）")
    @NotNull(message = "店铺类型不允许为空", groups = {ValidGroup.Create.class, ValidGroup.FrontCreate.class})
    @EnumValid(
            clazz = StoreType.class,
            message = "非法的店铺类型",
            method = "getType"
    )
    private String type;

    @ApiModelProperty("联系人")
    @NotNull(message = "联系人不允许为空", groups = {ValidGroup.Create.class, ValidGroup.FrontCreate.class})
    @Size(max = 60, message = "联系人长度不能超过60个字符")
    @JsonView(JsonViewProfile.App.class)
    private String contactName;

    @ApiModelProperty("联系电话")
    @NotNull(message = "联系电话不允许为空", groups = {ValidGroup.Create.class, ValidGroup.FrontCreate.class})
    @Size(min = 11, max = 11, message = "联系电话长度必须为11位")
    @Pattern(regexp = RegexpUtils.MOBILE_PHONE_REGEXP, message = "联系电话格式不符合要求")
    @JsonView(JsonViewProfile.App.class)
    private String contactMobile;

    @ApiModelProperty("是否展示店铺")
    @NotNull(message = "是否展示店铺不允许为空", groups = {ValidGroup.Create.class, ValidGroup.FrontCreate.class})
    @JsonView(JsonViewProfile.AppMch.class)
    private Boolean show;

    @ApiModelProperty("状态")
    @JsonView({JsonViewProfile.App.class, StoreView.ListCount.class})
    private String status;

    @ApiModelProperty("是否生效")
    @JsonView(JsonViewProfile.App.class)
    private Boolean enabled;

    @Excel(name = "是否允许营业时间外使用")
    @ApiModelProperty("是否允许营业时间外使用")
    @JsonView(JsonViewProfile.App.class)
    private Boolean useOutTime;
}
