﻿using System;
using Raven.Client;

namespace RpgRooms.Website
{
    public static partial class Functions
    {
        public static IRoom CreateRoom(
            this IDocumentSession documentSession,
            int ownerId,
            string slug,
            string title,
            string description)
        {
            documentSession.Ensure("session");
            slug.Ensure("slug");
            title.Ensure("title");

            var owner = GetMemberById(documentSession, ownerId);
            if (owner == null)
                throw new Exception(Strings.NoEntityForId("member", ownerId));

            var room = new Room
            {
                Slug = slug,
                Title = title,
                Description = description,
                OwnerId = owner.Id,
                OwnerAlias = owner.Alias,
                OwnerEmailAddress = owner.EmailAddress,
            };

            documentSession.Store(room);

            return room;
        }
    }
}