package com.gxwebsoft.cms.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.FieldStrategy;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * 单页（独立页面，如关于我们/联系方式/隐私政策/服务条款等）
 * 与文章不同：单页以固定 path（slug）访问，内容单独成篇，无栏目/分类概念。
 *
 * 状态约定（统一为后台前端习惯，避免与文章状态语义混淆）：
 *   0 草稿 / 1 已发布 / 2 已下线
 *
 * @author WorkBuddy
 * @since 2026-07-29
 */
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("cms_page")
@Schema(name = "CmsPage对象", description = "单页")
public class CmsPage implements Serializable {
    private static final long serialVersionUID = 1L;

    @Schema(description = "单页ID")
    @TableId(value = "page_id", type = IdType.AUTO)
    private Integer pageId;

    @Schema(description = "页面标题")
    private String title;

    @Schema(description = "访问路径(slug)，租户内唯一，如 about / contact / privacy")
    private String path;

    @Schema(description = "正文(富文本 HTML)")
    private String content;

    @Schema(description = "SEO 关键词")
    private String keywords;

    @Schema(description = "SEO 描述")
    private String description;

    @Schema(description = "封面/头图")
    private String image;

    @Schema(description = "模板标识(可选，留空则用站点当前模板)")
    private String template;

    @Schema(description = "排序(数字越小越靠前)")
    private Integer sortNumber;

    @Schema(description = "状态 0草稿 1已发布 2已下线")
    private Integer status;

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

    @Schema(description = "页面附件(JSON 数组字符串，元素含 name/url/size/ext/sort)；传 null 或空字符串可清空")
    @TableField(updateStrategy = FieldStrategy.IGNORED)
    private String attachments;

    @Schema(description = "阅读量")
    private Integer views;

    @Schema(description = "是否删除, 0否, 1是")
    @TableLogic
    private Integer deleted;

    @Schema(description = "租户id")
    private Integer tenantId;

    @Schema(description = "创建时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime createTime;

    @Schema(description = "修改时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime updateTime;

    @Schema(description = "状态文本")
    @TableField(exist = false)
    private String statusText;

    @Schema(description = "关联的导航栏目ID（cms_navigation.navigation_id），存于 cms_navigation.page_id；本实体不持久化该字段，仅作为 VO 透传与写回导航的入参")
    @TableField(exist = false)
    private Integer navigationId;

    public String getStatusText() {
        if (this.status == null) return "";
        switch (this.status) {
            case 0: return "草稿";
            case 1: return "已发布";
            case 2: return "已下线";
            default: return "";
        }
    }
}
