package com.multictrl.modules.business.dto;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.multictrl.common.constant.BusinessConstant;
import com.multictrl.common.validator.group.AddGroup;
import com.multictrl.common.validator.group.UpdateGroup;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.AssertTrue;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Null;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.io.Serial;
import java.io.Serializable;
import java.util.Date;


/**
 * 机库信息表
 *
 * @author Sdy
 * @since 1.0.0 2026-04-17
 */
@Data
@Schema(name = "机库信息表")
public class DockDTO implements Serializable {
    @Serial
    private static final long serialVersionUID = 1L;

    @Null(message = "{id.null}", groups = AddGroup.class)
    @NotNull(message = "{id.require}", groups = UpdateGroup.class)
    @Schema(description = "主键")
    private Long id;

    @NotBlank(message = "{dock.name.require}", groups = {AddGroup.class, UpdateGroup.class})
    @JsonProperty(required = true)
    @Schema(description = "机库名称")
    private String dockName;

    @NotBlank(message = "{dock.sn.require}", groups = {AddGroup.class, UpdateGroup.class})
    @JsonProperty(required = true)
    @Schema(description = "SN码")
    private String dockSn;

    @NotBlank(message = "{dock.type.require}", groups = {AddGroup.class, UpdateGroup.class})
    @JsonProperty(required = true)
    @Schema(description = "机库类型")
    private String dockType;

    //    @NotBlank(message = "{dock.model.require}", groups = {AddGroup.class, UpdateGroup.class})
//    @JsonProperty(required = true)
    @Schema(description = "机库型号")
    private String dockModel;

    @NotNull(message = "{dept.id.require}", groups = {AddGroup.class, UpdateGroup.class})
    @JsonProperty(required = true)
    @Schema(description = "所属部门")
    private Long deptId;

    @JsonProperty(access = JsonProperty.Access.READ_ONLY)
    @Schema(description = "机库经度")
    private Double dockLongitude;

    @JsonProperty(access = JsonProperty.Access.READ_ONLY)
    @Schema(description = "机库纬度")
    private Double dockLatitude;

    @JsonProperty(access = JsonProperty.Access.READ_ONLY)
    @Schema(description = "机库高度（椭球高）")
    private Double dockHeight;

    @JsonProperty(access = JsonProperty.Access.READ_ONLY)
    @Schema(description = "备降点经度")
    private Double deputyLongitude;

    @JsonProperty(access = JsonProperty.Access.READ_ONLY)
    @Schema(description = "备降点纬度")
    private Double deputyLatitude;

    @JsonProperty(access = JsonProperty.Access.READ_ONLY)
    @Schema(description = "备降点高度")
    private Double deputyHeight;

    @Schema(description = "备注")
    private String remarks;

    @JsonProperty(access = JsonProperty.Access.READ_ONLY)
    @Schema(description = "更新时间")
    private Date updateDate;

    @JsonProperty(access = JsonProperty.Access.READ_ONLY)
    @Schema(description = "图片地址")
    private String imgUrl;

    @JsonProperty(access = JsonProperty.Access.READ_ONLY)
    @Schema(description = "无人机型号")
    private String uavModel;

    @JsonProperty(access = JsonProperty.Access.READ_ONLY)
    @Schema(description = "是否在线")
    private Boolean online;

    @JsonProperty(access = JsonProperty.Access.READ_ONLY)
    @Schema(description = "机库模式")
    private String dockMode;

    @JsonIgnore
    @Schema(hidden = true)
    @AssertTrue(message = "机库型号不能为空", groups = {AddGroup.class, UpdateGroup.class})
    public boolean isDockModelValid() {
        if (!BusinessConstant.DJI_SIGN.equals(dockType)) {
            return StringUtils.isNotBlank(dockModel);
        } else {
            return true;
        }
    }
}
