package com.xiaoniu.system.groupgoods.groupbuying.dto;

import com.xiaoniu.common.core.resdata.BaseQueryDTO;
import com.xiaoniu.common.core.utils.StringUtils;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @Author haoxuyang
 * @Date 2024/10/18 9:23
 */
@Data
@Schema(description = "团购商品列表查询参数DTO")
public class GroupBuyingListQueryDTO extends BaseQueryDTO {
    @Schema(description = "商品类型")
    private Long goodsType;

    @Schema(description = "商品名称")
    private String goodsName;

    @Schema(description = "团购商品状态（1-上架 2-下架）")
    private Integer status;

    @Schema(description = "排序字段")
    private String sortCol;

    @Schema(description = "排序类型 1升序 2降序")
    private String sortType = "1";

    public String getSortCol() {
        if (StringUtils.isNotNull(sortCol)) {
            String regex = "([A-Z])";
            Matcher matcher = Pattern.compile(regex).matcher(sortCol);
            while (matcher.find()) {
                String target = matcher.group();
                sortCol = sortCol.replaceAll(target, "_" + target.toLowerCase());
            }
        }
        return sortCol;
    }

}
