import {AssetTypes} from "./asset-types";
import {SimpleSchema} from "simpl-schema/dist/SimpleSchema";

const AssetTypesSchema = new SimpleSchema({
	name: {
		type: String,
		label: "Name",
		optional: false,
		trim: true,
		index: 1,
		unique: true
	},
	tags: {  //An array of ProductTag names.  Note that we are not using the ProductTag ID's because I want a looser connection (if a ProductTag is deleted, it isn't a big deal if it isn't maintained in the Product records).
		type: [String],
		label: "Tags",
		optional: false,
		defaultValue: []
	},
	measures: {  //A JSON array of Measure ID's.
		type: Array,
		label: "Measures",
		optional: false,
		defaultValue: []
	},
	'measures.$': {
		type: String,
		label: "Measure ID",
		regEx: SimpleSchema.RegEx.Id
	},
	aliases: {  //A JSON array of alternate names.
		type: Array,
		label: "Aliases",
		optional: false,
		defaultValue: []
	},
	'aliases.$': {
		type: String
	},
	createdAt: {
		type: Date,
		label: "Created On",
		optional: false
	},
	updatedAt: {
		type: Date,
		label: "Updated On",
		optional: true
	},
	deactivated: {  //This is turned on first, if true it will hide the product in production views, but keep the product available in the sale views.  It is intended to be turned on for products that are no longer produced, but for which we have remaining inventory.
		type: Boolean,
		label: "Deactivated",
		optional: true
	},
	hidden: {  //Deactivated must first be true.  Hides the product everywhere in the system except in historical pages.  The inventory should be all sold prior to hiding a product.
		type: Boolean,
		label: "Hidden",
		optional: true
	},
	timestamp: {
		type: Date,
		label: "Timestamp",
		optional: true
	},
	weekOfYear: {
		type: Number,
		label: "Week Of Year",
		optional: true
	},
	amount: {
		type: Number,
		label: "Amount",
		optional: false,
		decimal: true
	},
	price: {
		type: Number,
		label: "Price",
		optional: false,
		min: 0,
		exclusiveMin: true,
	},
	assigneeType: {
		type: SimpleSchema.Integer,
		label: "Assignee Type",
		optional: false,
		min: 1,
		max: 2,
		exclusiveMin: false,
		exclusiveMax: false,
	},
});

AssetTypes.attachSchema(AssetTypesSchema);
