package com.cf.imes.module.system.controller.admin.organ.vo.organ;

import com.cf.imes.framework.common.validation.Mobile;
import com.cf.imes.framework.common.validation.NumberValid;
import com.cf.imes.framework.jackson.core.databind.LocalDateDeserializer;
import com.cf.imes.module.system.validation.common.CommonStatus;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.Valid;
import lombok.Data;

import jakarta.validation.constraints.*;

import java.time.LocalDate;
import java.util.List;

@Schema(description = "管理后台 - 组织创建/修改 Request VO")
@Data
public class OrganSaveReqVO {

    @Schema(description = "组织编号", example = "1024")
    private Long id;

    @Schema(description = "组织名", requiredMode = Schema.RequiredMode.REQUIRED, example = "晨丰")
    @NotNull(message = "组织名不能为空")
    @Size(min = 1, max = 30, message = "组织名长度不能超过30个字符")
    private String name;

    @Schema(description = "管理员姓名", requiredMode = Schema.RequiredMode.REQUIRED, example = "晨丰")
    @NotNull(message = "管理员姓名不能为空", groups = {OrganSaveCreateGroup.class})
    @Size(min = 1, max = 30, message = "管理员姓名长度不能超过30个字符", groups = {OrganSaveCreateGroup.class})
    private String orgAdminName;

    @Schema(description = "管理员账号", example = "15601691300")
    @Mobile
    @NotNull(message = "管理员账号不能为空", groups = {OrganSaveCreateGroup.class})
    @Size(max = 11, message = "管理员账号（手机号）长度不能超过11个字符", groups = {OrganSaveCreateGroup.class})
    private String orgAdminMobile;

    @Schema(description = "组织状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
    @NotNull(message = "组织状态")
    @CommonStatus
    private Integer status;

    @Schema(description = "绑定域名", example = "https://www.cf.com")
    @Size(max = 255, message = "绑定域名长度不能超过255个字符")
    private String website;

    @Schema(description = "组织套餐编号", example = "1024")
    private Long packageId;

    @Schema(description = "过期时间", requiredMode = Schema.RequiredMode.REQUIRED)
    @NotNull(message = "过期时间不能为空")
    @JsonDeserialize(using = LocalDateDeserializer.class)
    private LocalDate expireTime;

    @Schema(description = "账号数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
    @NotNull(message = "账号数量不能为空")
    @NumberValid(name = "账号数量")
    @Min(value = 1 , message = "组织账号数量必须大于0")
    @Max(value = 1000 , message = "组织账号数量不能超过1000")
    private Integer accountCount;

    // ========== 仅【创建】时，需要传递的字段 ==========

    @Schema(description = "用户账号", requiredMode = Schema.RequiredMode.REQUIRED, example = "chenfeng")
    @Pattern(regexp = "^[a-zA-Z0-9]{4,30}$", message = "用户账号由 数字、字母 组成")
    @Size(min = 4, max = 30, message = "用户账号长度为 4-30 个字符")
    private String username;

    @Schema(description = "密码", requiredMode = Schema.RequiredMode.REQUIRED, example = "123456")
    @Size(min = 4, max = 16, message = "密码长度为 4-16 位")
    private String password;

    @Schema(description = "是否大型组织")
    private Boolean large;

    @Schema(description = "地址")
    @Size(max = 255, message = "地址长度不能超过255个字符")
    private String address;

    @Schema(description = "备注")
    @Size(max = 200, message = "备注长度不能超过200个字符")
    private String remark;

    @Schema(description = "省")
    @Size(max = 64, message = "省名称长度不能超过64个字符")
    private String province;

    @Schema(description = "市")
    @Size(max = 64, message = "市名称长度不能超过64个字符")
    private String city;

    @Schema(description = "区")
    @Size(max = 64, message = "区名称长度不能超过64个字符")
    private String county;

    @Schema(description = "地区编码")
    @Size(max = 64, message = "地区编码长度不能超过64个字符")
    private String areaCode;

    @Schema(description = "经度")
    @Size(max = 64, message = "经度长度不能超过64个字符")
    private String longitude;

    @Schema(description = "纬度")
    @Size(max = 64, message = "纬度长度不能超过64个字符")
    private String latitude;

    @Schema(description = "是否开启灰度，0：开启、1：关闭", example = "0")
    @CommonStatus
    private Integer grayStatus;

    @Schema(description = "产品购买列表")
    @Size(min = 1, max = 10, message = "创建组织时最少需要购买1个产品", groups = {OrganSaveCreateGroup.class})
    @Valid
    private List<OrganCreateProductPurchaseReqVO> productPurchaseReqVOS;
}
