const { number, object, string, boolean } = require('yup');

const RssModel = require('../RssModel');
const RELATIONSHIP_SOURCE = require('../../constant/relationship/source.constant');

class Room extends RssModel {
  constructor(payload = {}) {
    super(payload);
  }

  // eslint-disable-next-line class-methods-use-this
  schema() {
    return object().shape({
      id: string().required(),
      buildingId: string().required(),
      floorId: string().required(),
      buildingKey: string().required(),
      floorKey: string().required(),
      roomKey: string().required(),
      name: string().max(128).trim().required().label('Name'),
      roomNumber: string().max(128).trim().required().label('Room Name'),
      size: number()
        .transform((value) => value || null)
        .nullable()
        .min(0, 'Size must be a positive number')
        .max(99999999999)
        .default(null)
        .label('Size'),
      source: string()
        .oneOf(Object.keys(RELATIONSHIP_SOURCE))
        .default(RELATIONSHIP_SOURCE.RSS)
        .required()
        .label('Source'),
      active: boolean(),
      mergedRoomId: string().nullable().default(null),
    });
  }
}

module.exports = Room;
