package com.reading.platform.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.reading.platform.common.serializer.UpperCaseSerializer;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.time.LocalDateTime;

/**
 * 租户实体（幼儿园/机构）
 */
@Data
@TableName("t_tenant")
@Schema(description = "租户信息")
public class Tenant {

    @Schema(description = "租户 ID", accessMode = Schema.AccessMode.READ_ONLY)
    @TableId(type = IdType.ASSIGN_ID)
    private String id;

    @Schema(description = "租户名称", example = "阳光幼儿园", requiredMode = Schema.RequiredMode.REQUIRED)
    private String name;

    @Schema(description = "登录账号", example = "sunshine", requiredMode = Schema.RequiredMode.REQUIRED)
    @JsonProperty("loginAccount")
    private String code;

    @Schema(description = "联系人姓名", example = "张三", requiredMode = Schema.RequiredMode.REQUIRED)
    @JsonProperty("contactPerson")
    private String contactName;

    @Schema(description = "联系人手机号", example = "13800138000")
    private String contactPhone;

    @Schema(description = "联系人邮箱", example = "zhangsan@example.com")
    private String contactEmail;

    @Schema(description = "地址", example = "北京市朝阳区 XX 路 XX 号")
    private String address;

    @Schema(description = "Logo URL")
    private String logoUrl;

    @Schema(description = "状态", example = "active", allowableValues = {"active", "inactive"})
    @JsonSerialize(using = UpperCaseSerializer.class)
    private String status;

    @Schema(description = "到期时间", example = "2025-12-31 23:59:59")
    @JsonProperty("expireDate")
    private LocalDateTime expireAt;

    @Schema(description = "学生配额", example = "500")
    @JsonProperty("studentQuota")
    private Integer maxStudents;

    @Schema(description = "教师配额", example = "50")
    @JsonProperty("teacherQuota")
    private Integer maxTeachers;

    @Schema(description = "创建人用户名", accessMode = Schema.AccessMode.READ_ONLY)
    @TableField(fill = FieldFill.INSERT)
    private String createdBy;

    @Schema(description = "更新人用户名", accessMode = Schema.AccessMode.READ_ONLY)
    @TableField(fill = FieldFill.INSERT_UPDATE)
    private String updatedBy;

    @Schema(description = "创建时间", accessMode = Schema.AccessMode.READ_ONLY)
    @TableField(fill = FieldFill.INSERT)
    private LocalDateTime createdAt;

    @Schema(description = "更新时间", accessMode = Schema.AccessMode.READ_ONLY)
    @TableField(fill = FieldFill.INSERT_UPDATE)
    private LocalDateTime updatedAt;

    @TableLogic
    private Integer deleted;

    // Not persisted - used in create response to return temp password
    @TableField(exist = false)
    private String tempPassword;

}
