package com.sqx.modules.address.query;

import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.sqx.common.query.PageQuery;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.util.StringUtils;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Date;

/**
 * 内部地址查询
 * @author codingliang
 * @date 2025-09-13
 */
@Data
public class InsideAddressQuery extends PageQuery {

    @ApiModelProperty("地址详情")
    private String addressDetail;

    @ApiModelProperty("状态")
    private String status;

    @ApiModelProperty("站点id")
    private Long stationId;

    @ApiModelProperty("查询开始时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date startTime;

    @ApiModelProperty("查询结束时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date endTime;

    @ApiModelProperty(value = "登录人id")
    private String userId;

    public String toStrMessage() {
        DateTimeFormatter dateTimeFormatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        StringBuilder stringBuilder=new StringBuilder();
        stringBuilder
                .append(StringUtils.hasText(addressDetail)?"地址详情："+addressDetail+";":"")
                .append(ObjectUtils.isNotEmpty(startTime) ?"查询开始时间："+ LocalDateTime.ofInstant(startTime.toInstant(), ZoneId.systemDefault()).format(dateTimeFormatter1)+";":"")
                .append(ObjectUtils.isNotEmpty(endTime)?"查询结束时间："+LocalDateTime.ofInstant(endTime.toInstant(), ZoneId.systemDefault()).format(dateTimeFormatter1)+";":"");
        if(StringUtils.hasText(status)){
            switch (status){
                case "1": stringBuilder.append("状态：启用;");break;
                case "0": stringBuilder.append("状态：禁用;");break;
            }
        }
        return stringBuilder.toString();
    }

    public String toStrCode() {
        DateTimeFormatter dateTimeFormatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        return
                ","+(addressDetail==null?"":addressDetail)
                        +","+(status==null?"":status)
                        +","+(stationId==null?"":stationId)
                        +","+(startTime==null?"":LocalDateTime.ofInstant(startTime.toInstant(), ZoneId.systemDefault()).format(dateTimeFormatter1))
                        +","+(endTime==null?"":LocalDateTime.ofInstant(endTime.toInstant(), ZoneId.systemDefault()).format(dateTimeFormatter1))
                        +",";
    }
}
