"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.PageStatus = exports.SpecialThumbType = void 0;
// oms/src/models/artModel.ts
const mongoose_1 = __importStar(require("mongoose"));
// --- 定义常量 (使用 TypeScript 枚举或常量对象) ---
// Special 缩略图类型
var SpecialThumbType;
(function (SpecialThumbType) {
    SpecialThumbType[SpecialThumbType["OUTLINE"] = 0] = "OUTLINE";
    SpecialThumbType[SpecialThumbType["GRAY"] = 1] = "GRAY";
    SpecialThumbType[SpecialThumbType["UPLOAD"] = 2] = "UPLOAD";
    SpecialThumbType[SpecialThumbType["GRADIENT"] = 3] = "GRADIENT";
})(SpecialThumbType || (exports.SpecialThumbType = SpecialThumbType = {}));
// 页面状态
var PageStatus;
(function (PageStatus) {
    PageStatus[PageStatus["REFUSE"] = 500] = "REFUSE";
    PageStatus[PageStatus["NEW"] = 1000] = "NEW";
    PageStatus[PageStatus["MODIFY"] = 2000] = "MODIFY";
    PageStatus[PageStatus["TESTING"] = 3000] = "TESTING";
    PageStatus[PageStatus["READY"] = 7000] = "READY";
    PageStatus[PageStatus["OFFLINE"] = 8000] = "OFFLINE";
    PageStatus[PageStatus["ONLINE"] = 9000] = "ONLINE";
})(PageStatus || (exports.PageStatus = PageStatus = {}));
// 定义 Art Schema
const ArtSchema = new mongoose_1.Schema({
    status: { type: Number, required: true, index: true, default: 1000 /* desc: '状态' */ },
    pageId: { type: mongoose_1.Schema.Types.ObjectId, required: true /* desc: 'Page Id' */ },
    user: { type: mongoose_1.Schema.Types.ObjectId, ref: "Designer", required: true, index: true /* desc: '作者' */ },
    from: { type: String /* desc: '素材来源' */ },
    work: { type: mongoose_1.Schema.Types.ObjectId, ref: "ArtBin" /*desc: '上色效果',*/ }, // 👈 关键修改：添加 work 字段到 Schema
    pageVersion: { type: Number, default: 1 /* desc: '底稿版本' */ },
    areaCount: { type: Number, required: true /* desc: '区块数' */ },
    areaCountFloor: { type: Number, required: true, index: true /* desc: '区块数/100向下取整' */ },
    coloredAreaCount: { type: Number, default: 0 /* desc: '填色区块数' */ },
    colorCount: { type: Number, default: 0 /* desc: '颜色数' */ },
    orderedColorCount: { type: Number, default: 0 /* desc: '已排序颜色数' */ },
    colorOrderStatus: { type: Number, default: 0 /* desc: '排序状态' */ },
    mapVersion: { type: Number, required: true, default: 1 /* desc: 'map版本' */ },
    workVersion: { type: Number, required: true, default: 1 /* desc: 'work版本' */ },
    centersVersion: { type: Number, required: true, default: 0 /* desc: '中心点版本' */ },
    hasSpecial: { type: Boolean, default: false, index: true /* desc: '是否有special' */ },
    specialVersion: { type: Number, default: 0 /* desc: 'Special图版本' */ },
    specialPkmVersion: { type: Number, default: 0 /* desc: 'SpecialPkm版本' */ },
    useSpecialThumb: { type: Number, required: true, default: 0 /* desc: '当前Special缩略图' */ },
    mystery: { type: Boolean, default: false, index: true /* desc: '是否神秘图' */ },
    ai: { type: Boolean, default: false, index: true /* desc: '是否AI参考图' */ },
    aiPrompt: { type: String /* desc: 'AI关键字' */ },
    width: { type: Number, required: true, index: true /* desc: '宽' */ },
    height: { type: Number, index: true, required: true /* desc: '高' */ },
    name: { type: String, required: true /* desc: '作品名' */ },
    desc: { type: String /* desc: '作品描述' */ },
    use: { type: String, required: true, index: true, default: "normal", lowercase: true, trim: true /* desc: '用途' */ },
    tags: { type: [String], index: true, lowercase: true, trim: true /* desc: '标签' */ },
    epgs: { type: [String], index: true, trim: true /* desc: 'EPG' */ },
    date: { type: Date, default: Date.now, index: true /* desc: '上传时间' */ },
    lastMod: { type: Date, default: Date.now, index: true /* desc: '修改时间' */ },
    timeSubmit: { type: Date, index: true /* desc: '提测时间' */ },
    timeReady: { type: Date, index: true /* desc: '通过时间' */ },
    refuseReason: { type: String /* desc: '拒稿原因' */ },
    lock: { type: Boolean, default: false, index: true /* desc: '是否上锁' */ },
    publishVersion: { type: Number, default: 0, index: true /* desc: '发布版本' */ },
    publishTime: { type: Date, index: true /* desc: '发布时间' */ },
    publishBy: { type: mongoose_1.Schema.Types.ObjectId, ref: "Designer", index: true /* desc: '发布者' */ },
    order: { type: Number, default: 0, index: true },
    drop: { type: Boolean, default: false, index: true /* desc: '标记删除' */ },
    dropReason: { type: String /* desc: '删除原因' */ },
    score: { type: Number /* desc: '评分' */ },
    ////////////////////////// 统计数据 ////////////////////////////
    totalStartCount: { type: Number, index: true /* desc: '总开始数' */ },
    totalDoneCount: { type: Number, index: true /* desc: '总完成数' */ },
    completionRate: { type: Number, index: true /* desc: '完成比例' */ },
}, {
    strict: true,
    toJSON: {
        virtuals: true,
        transform: artTransform,
    },
    toObject: {
        virtuals: true,
        transform: artTransform,
    },
});
// Art 转换函数 (虚拟字段 thumb 的逻辑)
function artTransform(doc, ret) {
    // make thumb for art.
    // 确保 doc.lastMod 存在或提供默认值，以避免运行时错误
    const lastModTime = doc.lastMod ? doc.lastMod.getTime() : Date.now();
    ret.thumb = `/thumbs/v2/page/320/${doc.pageId}.png?t=${lastModTime}`;
    if (doc.work && doc.hasSpecial) {
        ret.thumb = `/thumbs/v2/special/320/${doc._id}.png?t=${lastModTime}`;
    }
    else if (doc.work) {
        ret.thumb = `/thumbs/v2/work/320/${doc._id}.png?t=${lastModTime}`;
    }
}
// 复合索引
ArtSchema.index({
    order: -1,
    publishTime: -1,
});
// 创建并导出 Art Model
const Art = mongoose_1.default.model("Art", ArtSchema);
exports.default = Art;
