const mongoose = require("mongoose");

const gridCellSchema = new mongoose.Schema(
  {
    x: { type: Number, required: true, min: 1, max: 90 },
    y: { type: Number, required: true, min: 1, max: 90},
    color: { type: Number, required: true },
  },
  { timestamps: true }
);

gridCellSchema.index({ x: 1, y: 1 }, { unique: true });

gridCellSchema.methods.toDisplayColor = function () {
  if (this.color.startsWith("#")) return this.color;
  return `#${this.color}`;
};

const GridCell = mongoose.model("GridCell", gridCellSchema);

module.exports = GridCell;
