var config = require('../config');
var keystone = require('arch-keystone');
var transform = require('model-transform');
var Types = keystone.Field.Types;

var Magazine = new keystone.List('Magazine', {
    map: { name: 'title' },
    defaultSort: '-createTime',
});
var bucket = config['options']['gcs config']['bucket']

Magazine.add({
    title: { label: '標題', type: String, required: true, initial: true },
    issue: { label: '期數', type: String, required: true, initial: true },
    state: { label: '狀態', type: Types.Select, options: 'draft, published', default: 'draft', index: true },
    description: { label: '敘述', type: Types.Html, wysiwyg: true, height: 150 },
    magazine: {
        type: Types.GcsFile,
        initial: true,
        autoCleanup: true,
        datePrefix: 'YYYYMMDDHHmmss',
        bucket: bucket,
        destination: 'assets/magazine/',
        publicRead: true,
    },
    coverPhoto: { type: Types.ImageRelationship, ref: 'Image' },
    publishedDate: { label: '發佈日期', type: Types.Datetime, index: true, utc: true, default: Date.now, dependsOn: { '$or': { state: [ 'published', 'scheduled' ] } }},
    createTime: { type: Types.Datetime, default: Date.now, utc: true },
});


transform.toJSON(Magazine);
Magazine.defaultColumns = 'title, magazine, issue';
Magazine.register();

@@ -956,24 +956,131 @@
  'Image' %7D,%0A
+    type: %7B label: '%E7%A8%AE%E9%A1%9E', type: Types.Select, options: 'weekly, special', default: 'weekly', index: true %7D,%0A
     publishe
@@ -1232,16 +1232,127 @@
 %5D %7D %7D%7D,%0A
+    state: %7B label: '%E7%8B%80%E6%85%8B', type: Types.Select, options: 'published, archived', default: 'draft', index: true %7D,%0A
     crea

add type to the magazine model